How to Set Textview Textstyle Such as Bold, Italic

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



Leave a reply



Submit