相关疑难解决方法(0)

getString()和getText()有什么区别?

我尝试使用getString()从我的字符串中获取字符串string.xml
.我刚刚发现该getText()方法可以从我的资源中获取HTML标签!

说:

<string name="mySTring"><b><i>Hello Guys</i></b></string>
Run Code Online (Sandbox Code Playgroud)

它让我感到惊讶,因为我不得不用来Html.fromHtml()获取HTML标签 - 这是不推荐使用的.

这两种方法有什么区别?
有优势还是劣势?

html android

20
推荐指数
1
解决办法
4523
查看次数

我想将文本视图作为可点击的链接

<TextView
    android:id="@+id/link"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="Forget password?"
    android:autoLink="all"
    android:linksClickable="true"
    android:textColor="@color/lgreen"
    android:textStyle="italic"
     />
Run Code Online (Sandbox Code Playgroud)

Android正在突出显示TextView中的链接,但它们不响应点击.有人可以告诉我,我怎么能做到这一点作为一个可点击并移动到另一个链接.我通过看例子尝试了很多次.但我不能.有人可以清楚地向我解释如何将文本视图更改为可点击链接.

android hyperlink textview clickable

16
推荐指数
4
解决办法
8万
查看次数

显示HTML格式化字符串

我需要一个示例,说明如何使用简单的html将标记的字符串显示到TextView中.我找到了"跨越fromHtml(字符串源代码)",但我不知道如何将其插入到我的java代码中.

这是我的Java:

package com.SorenWinslow.TriumphHistory;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class TriumphHistory extends ListActivity {
    String[] HistoryList;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ArrayAdapter<String> adapter;
        HistoryList = getResources().getStringArray(R.array.history);
        adapter = new ArrayAdapter<String> (this,R.layout.historylistlayout,HistoryList);
        setListAdapter(adapter);

    }
}
Run Code Online (Sandbox Code Playgroud)

以下是历史样本:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="history">
<item><b>1883</b><br/>Some stuff happened</item>
<item><b>1884</b><br/>Some more stuff happened <i>before</i> the other stuff
</item>
<resources>
Run Code Online (Sandbox Code Playgroud)

这是我的historylistlayout.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:textColor="#ffffff" …
Run Code Online (Sandbox Code Playgroud)

java eclipse android android-arrayadapter

9
推荐指数
3
解决办法
4万
查看次数

如何在android中的string.xml中添加带有多个段落的长文本

当我在之间添加许多段落时

<string name="bbb"> ...... </string>
Run Code Online (Sandbox Code Playgroud)

它向我显示了以下错误.

[2014-12-22 14:54:55 - Inspiration] Her father rescued her from the heartless husband  and she was back her to the 
[2014-12-22 14:54:55 - Inspiration] G:\adt-bundle-windows-x86_64-20140702\workspace\Inspiration\res\layout\activity_women.xml:11: error: Error: No resource found that matches the given name (at 'text' with value '@string/Women1').
Run Code Online (Sandbox Code Playgroud)

xml android android-layout android-activity

6
推荐指数
2
解决办法
1万
查看次数

更改颜色并在 xml 中将 TextView 的部分加粗

这是我的xml代码activity_main.xml

<TextView
    ...
    android:text="@string/already_have_an_account" />
Run Code Online (Sandbox Code Playgroud)

并在strings.xml

<string name="already_have_an_account">Already have an account? <font color='#FF6200EE'>Log In</font></string>
Run Code Online (Sandbox Code Playgroud)

使用此代码,我可以更改“登录”文本的颜色,但我想在xml代码中将其设置为粗体,而不是Java

如何实现这一目标?

html xml android textview

2
推荐指数
1
解决办法
1191
查看次数