我在我的应用程序中使用了TextView。我需要在程序中改变TextView的字体类型。在按钮点击函数中,我需要改变TextView的字体类型。如果当前字体类型是Normal,那么我需要将其转换为Bold(反之亦然)。如果有人知道答案,请与我分享。谢谢。
要在程序中使TextView加粗,可以这样做:
textView.setTypeface(null, Typeface.BOLD);
要将其恢复为正常状态,请执行以下操作:
textView.setTypeface(null, Typeface.NORMAL);
要获取当前的字体,请使用getTypeface()
http://developer.android.com/reference/android/widget/TextView.html#getTypeface()
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)