Is there a way to set the textStyle attribute of a TextView programmatically? There doesn\'t appear to be a setTextStyle() method.
So many way to achieve this task some are below:-
1.
String text_view_str = "Bolded text, italic text, even underlined!";
TextView tv = (TextView)findViewById(R.id.ur_text_view_id);
tv.setText(Html.fromHtml(text_view_str));
2.
tv.setTypeface(null, Typeface.BOLD);
tv.setTypeface(null, Typeface.ITALIC);
tv.setTypeface(null, Typeface.BOLD_ITALIC);
tv.setTypeface(null, Typeface.NORMAL);
3.
SpannableString spannablecontent=new SpannableString(o.content.toString());
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),
0,spannablecontent.length(), 0);
// set Text here
tt.setText(spannablecontent);
4.
tv.setTextAppearance(getApplicationContext(), R.style.boldText);
or if u want through xml
android:textStyle="normal"
android:textStyle="normal|bold"
android:textStyle="normal|italic"
android:textStyle="bold"
android:textStyle="bold|italic"