ThisCaaaaaa on the spot. ...">

Android: Make characters bold in xml

I write this line in the strings.xml file:

<string name="Help">This<b>Caaaaaa</b> on the spot.</string> 

But the characters between the <b> not in bold. What am I doing wrong? PS: I just want to make part of the line (for example, "Caaaaa" above) in bold.

+6
source share
4 answers

When you set the text of some widget to this line, use the following code:

In strings.xml use this to add a ur string:

 <string name="Help"> <![CDATA[ This <b>Caaaaaa</b> on the spot. ]]> </string> 

In your activity

 yourWidget.setText(Html.fromHtml(getString(R.string.Help))); 
+23
source

I think you cannot do this in the string.xml file.

but you can set textStyle = "bold" where you use it.

as -

 <TextView android:textSize="18dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@color/white" android:textStyle="bold" android:text="@string/Help" android:id="@+id/header"> </TextView> 
+1
source

Tags in XML, such as <string> and <b> have no intrinsic meaning. The <b> only means "bold" if the XML processing software considers it to be bold and treats it as bold. You did not say which software processes XML.

If it were HTML, not XML, that would be a different matter.

+1
source

Take a look here . You can set the text style in the XML layout file.

0
source

Source: https://habr.com/ru/post/899585/


All Articles