I am using textview in my application. In that I need to change the typeface for the textview programmatically. In a button click function i need to change the textview typeface. If typeface is Normal means i need to convert to Bold(Vice versa). If anybody knows the answer means kindly share with me. Thanks.

有帮助吗?

解决方案

To make your textView bold programmatically do:

textView.setTypeface(null, Typeface.BOLD);

To set it back to normal do:

textView.setTypeface(null, Typeface.NORMAL);

To get the current typeface use getTypeface()

http://developer.android.com/reference/android/widget/TextView.html#getTypeface()

其他提示

try this

TextView textview= (TextView) findViewById(R.id.appname)
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
textView.setTypeface(null, Typeface.BOLD_ITALIC);
setTypeface(Typeface tf, int style)

Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.

From the Android documentation

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top