How do you change text/font settings in an Android TextView
?
For example, how do you make the text bold
To do this in the layout.xml
file:
android:textStyle
Examples:
android:textStyle="bold|italic"
Programmatically the method is:
setTypeface(Typeface tf)
Sets the typeface and style in which the text should be displayed. Note that not all Typeface
families actually have bold and italic variants, so you may need to use setTypeface(Typeface, int)
to get the appearance that you actually want.
editText.setTypeface(Typeface.createFromAsset(getAssets(), ttfFilePath));
etitText.setTypeface(et.getTypeface(), Typeface.BOLD);
will set both typface as well as style to Bold.
Assuming you are a new starter on Android Studio, Simply you can get it done in design view XML by using
android:textStyle="bold" //to make text bold
android:textStyle="italic" //to make text italic
android:textStyle="bold|italic" //to make text bold & italic
in file .xml, set
android:textStyle="bold"
will set text type is bold.
For case where you are using custom fonts, but do not have bold typeface for the font you can use:
myTextView.setText(Html.fromHtml("<b>" + myText + "</b>");
Simply you can do the following:
Set the attribute in XML
android:textStyle="bold"
Programatically the method is:
TextView Tv = (TextView) findViewById(R.id.TextView);
Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
Tv.setTypeface(boldTypeface);
Hope this helps you thank you.