How to set TextView textStyle such as bold, italic
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
textView.setTypeface(null, Typeface.NORMAL);
To keep the previous typeface
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC)
Make TextView Bold Italic etc
Use this
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
When you are passing null it returns the default Typeface
How to set the font style to bold, italic and underlined in an Android TextView?
I don't know about underline, but for bold and italic there is "bolditalic"
. There is no mention of underline here: http://developer.android.com/reference/android/widget/TextView.html#attr_android:textStyle
Mind you that to use the mentioned bolditalic
you need to, and I quote from that page
Must be one or more (separated by '|') of the following constant values.
so you'd use bold|italic
You could check this question for underline: Can I underline text in an android layout?
Set bold and italic style in a textview with custom font (Programatically)
You need to have a font which is both bold and italic, that's how fonts work. Unfortunately Android cannot just combine those as it's not that easy, so you need to have your own file.
how to make a specific text on TextView BOLD
Just build your String in HTML and set it:
String sourceString = "<b>" + id + "</b> " + name;
mytextview.setText(Html.fromHtml(sourceString));
Custom TextView with Bold, Normal & Italic Styles
try this:
textview.setTypeface(typeface, Typeface.BOLD);
you can use also ITALIC
and BOLD_ITALIC
for custom textview use:
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTextView(Context context) {
super(context);
}
public void setTypeface(Typeface tf, int style) {
if (style == Typeface.BOLD) {
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/fonts_name")/*, -1*/);
} else {
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/fonts_name")/*, -1*/);
}
}
}
Related Topics
How to Create a User-Defined Function in SQLite
How to Launch Termux Through Another Android App
Multi Flavor App Based on Multi Flavor Library in Android Gradle
Android: Speech Recognition Without Using Google Server
HTML List Tag Not Working in Android Textview. What How to Do
Get and Parse CSV File in Android
How to "Select Android Sdk" in Android Studio
Software Keyboard Resizes Background Image on Android
How to Hide the System Bar in Android 3.0? It's an Internal Device and I'm Managing Navigation
Listview with Clickable/Editable Widget
Android 2.1 Programmatically Unmount Sdcard
Detect from Browser If a Specific Application Is Installed in Android
Android Background Image Size in Pixel
Why Do I Get "Unresolved Reference" Error for My View's Name/Id When I Type It in Kotlin
How to Do Http Authentication in Android