0

我在strings.xml 中有一个字符串数组。如何在项目中的字符串下划线?

对于字符串,我们这样做..

  <string name="clickable_string">This is a <u>clickable string</u></string>

我尝试过这样的事情。

    <string-array name="products">
        <item>this is a <u> clickable</u> string </item>
        <item> <u> clickable</u> string </item>
        <item>this is a <u> clickable</u> string </item> 
     </string-array>

它不工作。我怎样才能做到这一点?谢谢

4

2 回答 2

2

试试这个方法会奏效

 <string-array name="description">
     <item> <Data> <![CDATA[ Check this <u>Redirect to Next Activity</u> ]]></Data> </item>
 </string-array>

在java代码中使用这个:

    ArrayList<String> title_list = new ArrayList<String>();
    String[] description_Array = getResources().getStringArray(R.array.description);
    String categoryAndDesc = null;
    for(String cad : description_Array) {
      categoryAndDesc = cad;
      title_list.add(categoryAndDesc);
    }
    CharSequence sequence = Html.fromHtml(categoryAndDesc);

    seperator_view.setText(strBuilder);
    seperator_view.setMovementMethod(LinkMovementMethod.getInstance());
于 2011-09-14T17:44:00.640 回答
1

试试这个:

<string name="clickable_string">This is a &lt;u&gt;clickable string&lt;/u&gt;</string>

(ie) 将 < 和 > 替换为 < 和> 在您的strings.xml中获取 HTML 格式的内容。

在您的代码中使用:

String text = context.getString(R.string.clickable_string);
myTextView.setText(Html.fromHtml(text));
于 2011-09-14T17:35:38.680 回答