Check if custom font can display character

前端 未结 6 972
感情败类
感情败类 2020-12-06 17:14

I have a custom font which is displaying the box character. The font I am using does not support all languages apparently. I want to check if the String I am about to displa

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 18:02

    For those of you who would still like your app to be compatible with APIs less than 23 and still use the hasGlyph function in your code, you can use the @TargetApi(23) in the following way:

    @TargetApi(23)
    public boolean isPrintable( String c ) {
        Paint paint=new Paint();
        boolean hasGlyph=true;
        hasGlyph=paint.hasGlyph(c);
        return hasGlyph;
    }
    

    And then in your code:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if(isPrintable(yourString)) {
            //Do Something
        }
    }
    

    The only problem is that in APIs lower than 23, your app may show blank symbols. But at least in API23+ your app will be perfect.

提交回复
热议问题