Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" />
like image 440
Nikunj Patel Avatar asked Dec 31 '25 16:12

Nikunj Patel


1 Answers

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.

like image 57
Ali Avatar answered Jan 02 '26 08:01

Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!