TextView中的度数符号(以摄氏度/华氏度为单位)

时间:2010-07-22 18:18:25

标签: android textview

有没有办法将小圆度符号包含在TextView中?这将用于温度读数,如摄氏度或华氏度。 我想知道是否有人以前以编程方式完成此操作。

7 个答案:

答案 0 :(得分:102)

您可以在Java中使用可用于摄氏度的Unicode符号:\u2103。对于华氏温度,您可以使用\u2109

我已经确认这适用于运行Android 2.3.6版的Android Nexus S.

示例代码:

temperatureValue.setText((result) + " \u2109");

答案 1 :(得分:18)

如果有人想要没有字母的小圆圈标志,他可以使用:

\u00B0

来源: Unicode Character 'DEGREE SIGN'

答案 2 :(得分:12)

在活动中 摄氏度

tempValue.setText((resultemp) + " \u2103");

for Fahrenheit

tempValue.setText((resultemp) + " \u2109");

代表凯尔文

tempValue.setText((resultemp) + " \u212A");

代表Romer

tempValue.setText((resultemp) + " \u00B0R");

在xml.file中 摄氏度

android:text="\u2103"

for Fahrenheit

android:text="\u2109"

代表凯尔文

android:text="\u212A"

代表Romer

android:text="\u00B0R"

答案 3 :(得分:1)

<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="\u00B0"/>

如果在android studio布局预览中看不到符号,则需要添加

xmlns:tools="http://schemas.android.com/tools"

到根xml元素。

答案 4 :(得分:0)

如果您只需要度(o)圆圈符号,则可以复制到代码下方。

char tmp = 0x00B0;
temperature.setText("60"+tmp);

希望有所帮助:)

答案 5 :(得分:0)

要在degree中显示TextView符号,可以在“ &#176; ”中使用而无需任何距离。如您在下面看到的示例:

`android:text =“ 10&#176; c” 因此,此命令将在屏幕android上将您显示为10°c。

答案 6 :(得分:0)

对于以 XML 格式显示,如果您想显示 android:text="32°C" 可以使用:

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"      
android:text="32&#xb0;C"
android:id="@+id/myTV"></TextView>

要以编程方式执行此操作,您可以使用:

myTV.setText("32" + (char) 0x00B0+"C");