Line size and font change in string.xml

In my Android app, I have to write a line to a file. Before that, I want to format the string in order to make the font bold and have a new text size. So I change string.xml to

  "<string name="file_title" ><b>#title*</b></string>", 

for bold text and writing to a text file. But it does not appear as bold in the file.

  • Is this the correct method that I used to implement the string in bold?
  • I also want to know how to resize a string text directly from string.xml

how to add this courage to a file ... i tried

  "<string name="note"><![CDATA[<b>title</b>]]></string>" 

in java code get a string

  yourtextview.setText(Html.fromHtml(getString(R.string.note))); 

using texview, it's a bold, exaclty that I want to write to a file using the code below

  "bufferWritter.write(String.valueOf(Html.fromHtml(getString(R.string.note))));" 

but I don’t see the courage in the print.txt file ...

Thanks and Regards Anoop

+4
source share
4 answers

try it

 in string.xml write like this <string name="note"><![CDATA[<b>title</b>]]></string> in java code get your string yourtextview.setText(Html.fromHtml(getString(R.string.note))); 
+2
source

You should try to use diameter.xml for size values.

then link to it @ dimen / yourDimensionName

Send this link to

Or another way is to use HTML from java code

I tried this to work.

In string.xml try

 <string name="test"><![CDATA[<b>test</b>]]></string> 

In your java code, settext is the string value from a string resource such as

  textview.setText(Html.fromHtml(getString(R.string.test))); 

Works great...

+2
source

This is the wrong way. Just resize it with xml directly. use.

 android:text="Date" android:textStyle="bold" android:textSize="xdp" 
0
source

To do this, you must have your xml resource as:

 <?xml version="1.0" encoding="utf-8"?> <resources> <string name="file_title"><b>title*</b>!</string> </resources> 

And then use:

 Resources res = getResources(); String text = res.getString(R.string.file_title); CharSequence styledText = Html.fromHtml(text); 

To change the text or other parameters, you can add a <span></span> with a specific CSS style in the text.

For more information, please check here: http://developer.android.com/guide/topics/resources/string-resource.html

Hope this helps!

0
source

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


All Articles