【问题标题】:How to underline the string in a string-array如何在字符串数组中为字符串加下划线
【发布时间】:2011-11-17 05:41:59
【问题描述】:

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

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

  <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>

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

【问题讨论】:

    标签: android xml underline


    【解决方案1】:

    试试这个方法就行了

     <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());
    

    【讨论】:

      【解决方案2】:

      试试这个:

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

      (即)将 替换为 &lt&semi;和>在您的 strings.xml 中获取 HTML 格式的内容。

      并在您的代码中使用:

      String text = context.getString(R.string.clickable_string);
      myTextView.setText(Html.fromHtml(text));
      

      【讨论】:

      • 谢谢@Raghunath ..对于字符串它的工作。我正在寻找字符串数组的解决方案..
      • 在 内做同样的事情 :)
      • 不@Raghunath ..它不是那样工作的......像venky说它工作但同样的字符串正在访问......数据的最后一个条目......谢谢你的回复。 .
      猜你喜欢
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 2013-07-20
      • 2015-04-17
      • 1970-01-01
      • 2016-10-13
      相关资源
      最近更新 更多