首页 文章

如何在android中获取自定义字体的类型面部样式?

提问于
浏览
0

使用自定义字体后,我无法通过以下方式获取文本视图的类型面样式(BOLD,ITALIC,BOLD_ITALIC):

textView.getTypeface.getStyle();

事实上,设置新类型的面部风格并不适用于textView,虽然我们可以看到风格在视觉上有所变化 . 我设置了这样的类型面部样式:

Typeface font = Typeface.createFromAsset(getAssets(), "sampleFont.ttf");
textView.setTypeface(font, Typeface.BOLD);

但,

textView.getTypeface.getStyle();

返回0(NORMAL)而不是1(BOLD)!当我尝试使用常规字体时,所有这些都会发生 .

1 回答

  • 0

    Typeface自API级别1以来也有isBold()isItalic()方法 .

    或试试这个

    if(textView.getTypeface()!=null){
       if(textView.getTypeface().getStyle()==Typeface.BOLD || textView.getTypeface().getStyle()==Typeface.ITALIC){
          //your code goes here
       }
    }
    

相关问题