4

In my android application, i have to write a string into a file. Before that I want to format the string to make the font bold and have a new text size. So I modify the string.xml by

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

for bold the text and wrote to text file. But it is not showing as bold in the file.

  1. Is that right method i used to implement the string bold?
  2. Also i want to know how to change the text size of a string direct from string.xml

how to add that boldness in file... i tried

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

in java code get your string

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

by using texview it"s coming bold , exaclty i want to write to file, using the below code

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

but i can"t see the boldness in my print.txt file...

Thanks & Regards Anoop

1

4 Answers 4

2

You Should try to use dimens.xml for dimension values

then reference it @dimen/yourDimensionName

Refer this link for

Or other way is using HTML from java code

I tried this is working.

In your string.xml file try this

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

In your java code settext this string value from string resource like this

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

Its working fine....

1

Try this

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
  • how to add that boldness in file... i tried bufferWritter.write(String.valueOf(Html.fromHtml(getString(R.string.note)))); Nov 3, 2012 at 7:23
  • @AnoopNarayan you are writing in bufferWritter if this text is directly set to your textview then this will in bold letter
    – J.D.
    Nov 3, 2012 at 9:20
0

This is not the right way. Just change its size from xml directly. use.

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

In order to do that, you should 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);

In order to change the text or other parameters, you can add a <span></span> with specific css style around your text.

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

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.