Android TextView 中的度数符号(如摄氏度/华氏度)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3312001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:39:45  来源:igfitidea点击:

Degrees symbol (as in Degrees Celsius/Fahrenheit) in a TextView

androidtextview

提问by Aurora

Is there a way to include the small circular degrees symbol to a TextView? This would be for temperature readings, as in degrees Celsius or Fahrenheit. I'm wondering if anyone has done this programmatically before.

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

回答by Luis Miguel Serrano

There is a Unicode symbol for Celsius degrees that you can use in Java: \u2103. For Fahrenheit you can use \u2109.

您可以在 Java 中使用一个表示摄氏度的 Unicode 符号:\u2103. 对于华氏度,您可以使用\u2109.

I have confirmed this works on Android Nexus S running Android version 2.3.6.

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

Example code:

示例代码:

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

回答by yshahak

If Someone wants just the little circle sign without the letter, he can use:

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

\u00B0

Source: Unicode Character 'DEGREE SIGN'

来源: Unicode 字符 'DEGREE SIGN'

回答by Phadadev

in Activity for Celsius

在摄氏活动中

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

for Fahrenheit

华氏度

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

for Kelvin

开尔文

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

for Romer

为罗默

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


In xml.file for Celsius

在 xml.file 中为摄氏

android:text="\u2103"

for Fahrenheit

华氏度

android:text="\u2109"

for Kelvin

开尔文

android:text="\u212A"

for Romer

为罗默

android:text="\u00B0R"

回答by Vasil Valchev

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

If sign is not visible on android studio layout preview, you need to add

如果在android studio布局预览上看不到标志,则需要添加

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

to the root xml element.

到根 xml 元素。

回答by Nihas Nizar

If you need only the degree (o) circle symbol you can copy below code.

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

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

Hope it helps :)

希望能帮助到你 :)