Reputation: 65
I am trying to insert superscript and subscript text into android button text. I have tried by giving the following in strings.xml file
<string name="NAME"><![CDATA[<sup><small>-1</small></sup>]]></string>
And in the MainActivity.java file,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
Button NAME = (Button) findViewById(R.id.button10);
NAME.setText(Html.fromHtml(getResources().getString(R.string.NAME)));
}
But i am unable to succeed.
Query:
Upvotes: 0
Views: 1223
Reputation: 16739
Problem : You are fetching wrong value.
Solution:
use R.string.NAME
instead of R.string.iHyperbolic
your NAME
carries the html string and not iHyperbolic
.
Is there any way to specify it in "strings.xml" file itself without using setText in code ?
AFAIK, You will have to use setText() to set the html string after it is processed by Html class. Cause Html class processes HTML strings into displayable styled text.And if you wish to display this Html styled text on a widget then you will have to use setText().
Upvotes: 1
Reputation: 169
Instead of writing:
<sup><small>-1</small></sup>
try writing:
<sup>-1</sup>
Hope helps :)
Upvotes: 0