【发布时间】:2014-05-15 03:42:36
【问题描述】:
我想在 textview 中动态显示文本。
例如:
喜欢红色标记。查看摄氏温度符号。
java代码:
TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp());
请帮帮我。
【问题讨论】:
我想在 textview 中动态显示文本。
例如:
喜欢红色标记。查看摄氏温度符号。
java代码:
TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp());
请帮帮我。
【问题讨论】:
TextView txt_footer = new TextView(this);
txt_footer.setLayoutParams(childLayoutParams);
txt_footer.setText(weather.getMinTemp() + " \u2109" + "C");
【讨论】:
你可以试试,
((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>"));
【讨论】:
试试这个让摄氏温度符号变成红色:
((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");
【讨论】: