Nikunj Patel
Nikunj Patel

Reputation: 22066

Insert & Symbol in Textview android:text

How can I insert & Symbol in <TextView>
I have tried with & and Hex code but not allow me to do this.

<TextView android:layout_height="wrap_content"
    android:textColor="#49515F"
    android:text="Mission and Philosophy" // & 
    android:textStyle="bold"
    android:textSize="11dp" 
    android:layout_width="wrap_content" />

Upvotes: 3

Views: 8623

Answers (4)

Nish
Nish

Reputation: 1

Use \u0026 in Unicode for "&"

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1 * * * \u0026" />

Output: 1 * * * &

Upvotes: 0

Lucifer
Lucifer

Reputation: 29672

please try this,

 android:text="Mission &amp; Philosophy"

It is called Escape Sequence.

Upvotes: 1

Ali
Ali

Reputation: 12684

I know if you externalize the string to string.xml you can definitely use &amp; to achieve the desired result. The same should work inline.

 <TextView android:layout_height="wrap_content"
                  android:textColor="#49515F"
                  android:text="Mission &amp; Philosophy" 
                  android:textStyle="bold"
                  android:textSize="11dp" 
                  android:layout_width="wrap_content" />

or

 <TextView android:layout_height="wrap_content"
                  android:textColor="#49515F"
                  android:text="@string/mission_philosophy" 
                  android:textStyle="bold"
                  android:textSize="11dp" 
                  android:layout_width="wrap_content" />

Then in strings.xml or really any xml file under res\values folder do:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="mission_philosophy">Mission &amp; Philosophy</string>
</resources>

The second approach is more desirable because if you never need to localize the app, all your strings will be in one xml file.

Upvotes: 8

zam664
zam664

Reputation: 767

Did you try the ampersand followed by amp and then a semi colon? I cannot do it here because the web site converts it.

Upvotes: 0

Related Questions