Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

degree symbol in TextView

I want to know how to make a degree symbol for an angle in a Text View (android). There are a few questions similar to this, I have tried them but they don't seem to work.

<TextView
    android:id="@+id/tv_counter"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:paddingBottom="20dp"

    android:text="..."

    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="80dp"
    android:textColor="#FFA500" />
like image 934
Jack Trowbridge Avatar asked Jan 08 '12 13:01

Jack Trowbridge


People also ask

How do you encode a degree?

Press and hold the ALT key and type 0 1 7 6 on the numeric keypad of your keyboard. Make sure the NumLock is on and type 0176 with the leading zero. If there is no numeric keypad, press and hold the Fn before typing the 0176 numbers of degree symbol.

How do you display the degree symbol in Java?

temp = temp. replaceAll(" ", "%20");


4 Answers

XML doesn't use C-style escapes, it uses HTML-style character entities. Try this:

android:text="50&#x2103;"

As you mention in the comment, U+2103 isn't what you want, you want this:

android:text="50&#xb0;"
like image 114
Ned Batchelder Avatar answered Oct 01 '22 17:10

Ned Batchelder


Try this:

android:text= "50&#x2103;"

See also Unicode in XML and other Markup Languages.

like image 21
Adam Zalcman Avatar answered Oct 01 '22 18:10

Adam Zalcman


In Code:

myTextView.setText ( "78" + (char) 0x00B0 );

                "OR"

In XML:

android:text="50&#x2103;"
like image 32
Maddy Avatar answered Oct 01 '22 19:10

Maddy


in xml - if you want just the symbol without F or C just use:

      "\u00B0"

like this:

      android:text="50\u00B0"
like image 24
Udi Reshef Avatar answered Oct 01 '22 17:10

Udi Reshef