Reputation: 559
I want increase font size of some part of the string before set to text view. Means My string is "Hello Stack over flow". Then I want font size of over is larger than other words and its bold.
Upvotes: 2
Views: 10004
Reputation: 133560
You can use a SpannableString
Example :
TextView tv = new TextView(this);
String string= "Hello";
String title="MyTitle";
SpannableString ss1= new SpannableString(string);
ss1.setSpan(new RelativeSizeSpan(2f), 0, ss1.length(), 0);
tv.append(ss1);
tv.append(title);
setContentView(tv);
Snap
You may also check
Using size HTML attribute in TextView
Searching for supported html tags
http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
http://bigknol.com/android-supported-html-tags-textview-string/
Upvotes: 6
Reputation: 1536
you can use html string to make some part bold for example
private String getHtmlText(String boldString,String restString){
String htmlString = "<b>" +boldString +"</b> " + restString;
return htmlString;
}
and then setText using Html.fromHtml(htmlString) like
yourTextView.setText(Html.fromHtml(getHtmlText(textBold,textNormal)));
Upvotes: 0
Reputation: 8251
Do something like below,
String str="<small>Hello Stack</small><big>Over</big>flow";
textview.setText(Html.fromHtml(str));
Upvotes: 6