【问题标题】:Display text in textview in android [closed]在android的textview中显示文本[关闭]
【发布时间】:2014-05-15 03:42:36
【问题描述】:

我想在 textview 中动态显示文本。

例如:

喜欢红色标记。查看摄氏温度符号。

java代码:

TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp());

请帮帮我。

【问题讨论】:

标签: android textview


【解决方案1】:
TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp()  + " \u2109" + "C");

【讨论】:

    【解决方案2】:

    你可以试试,

    ((TextView)findViewById(R.id.text)).setText(Html.fromHtml("8<sup>o</sup>"));
    

    这里sup被称为上标,也可以写下标

    ((TextView)findViewById(R.id.text)).setText(Html.fromHtml("8<sub>o</sub>"));
    

    【讨论】:

      【解决方案3】:

      试试这个让摄氏温度符号变成红色

      ((TextView)findViewById(R.id.text)).setText(Html.fromHtml("8<font color=""#f00"">°</font>"));
      

      请注意,我使用了 #ff0000 => #f00
      的缩写形式 您可能更喜欢使用命名颜色“红色”。

      这是为了使其颜色相同(不是红色):

      TextView txt_footer = new TextView(this);
      txt_footer.setLayoutParams(childLayoutParams);
      txt_footer.setText(weather.getMinTemp() + "°C");
      

      【讨论】:

        猜你喜欢
        • 2013-08-25
        • 2011-12-14
        • 1970-01-01
        • 2011-11-29
        • 2011-07-10
        • 2014-01-26
        • 2020-06-09
        • 1970-01-01
        • 2020-11-17
        相关资源
        最近更新 更多