代码之家  ›  专栏  ›  技术社区  ›  Darksymphony

Android TextView下划线不起作用

  •  4
  • Darksymphony  · 技术社区  · 7 年前

    我想做一件简单的事情-在TextView中为文本加下划线。字符串放置在字符串中。xml(由于翻译):

    <string name="mytext"><u>UnderlineText</u></string>
    

    然后我将文本以编程方式放置:

     TextView txt1 = findViewById(R.id.autor);
     txt1.setText(resources.getString(R.string.mytext));
    

    然而,由于某种原因 <u> 字符串中的文件被忽略,我的文本没有下划线。

    我还尝试了:

     txt1.setText(Html.fromHtml(resources.getString(R.string.mytext)));
    

    还是没什么。文本正常显示,不带下划线。

    2 回复  |  直到 7 年前
        1
  •  3
  •   Jose Alberto Navarro Barrios    7 年前

    替换此:

    <string name="mytext"><![CDATA[<u>UnderlineText</u>]]> </string>

        2
  •  3
  •   Richard Miller    5 年前

    尝试使用getText()而不是getString()。

    txt1.setText(resources.getText(R.string.mytext));
    

    这将返回包含样式的本地化字符串。