Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Bold Button Text

I have a button in my application. the text in the button goes as "Type: Location" something like that.

I'm wondering whether its possible to change the text on the button as "Type: Location"

i.e Bold the text partially on the button??

Thanks for yoru time in advance.

like image 411
Jay Mayu Avatar asked Sep 02 '11 10:09

Jay Mayu


People also ask

How do you turn on bold text on Android?

Double tap the text you want to format. Tap Format, then choose a formatting option like bolding, italics, or changing the font color.


2 Answers

we have a more better choice like this :android:textStyle="bold" android api support bold

like image 51
Yang Li Avatar answered Sep 27 '22 17:09

Yang Li


Simply put your string in strings.xml and change it like this,

 <string name="hello"><b>Hello</b> World, fh!</string>

and set this text to your button like this

<Button
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAllCaps="false"
    android:text="@string/hello"
    />

Sometimes the above approach will not be helpful when you might have to use Dynamic Text. So at that case SpannableString comes into action.

  String tempString="Copyright";
  Button button=(Button)findViewById(R.id.button);
  SpannableString spanString = new SpannableString(tempString);
  spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0);
  button.setText(spanString);
like image 32
Andro Selva Avatar answered Sep 27 '22 16:09

Andro Selva