检查Android的一个字体对象的家庭 [英] Check the family of a Typeface object in Android

查看:134
本文介绍了检查Android的一个字体对象的家庭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能检查字样的对象是使用什么样的家庭在Android的API 8?

Is it possible to check what family a Typeface object is using in Android API 8?

我喜欢这样一个Paint对象上创建的字体

I am creating the Typeface on a Paint object like so

//Simplified code, the user actually selects the family and style from a list
Paint paint = new Paint();
paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));

我后来想能够检查家庭像这样

I would later like to be able to check the family like so

Typeface tf= paint.getTypeface();

if (tf.equals(Typeface.DEFAULT) || tf.equals(Typeface.DEFAULT_BOLD)) {
    //do something
} else if (...) {
    //do something else
} 

这行不通,因为它们不是同一个对象,我也曾尝试 TF ==值却又同​​样的结果。字样的对象似乎不暴露任何有用的东西,帮助家庭发现,是有这样一个解决方法吗?我只需要检测基本的Andr​​oid字样(SERIF,无衬线,DEFAULT,MONOSPACE等)

This does not work as they are not the same object, I have also tried tf == value but again the same result. The Typeface object does not appear to expose anything useful to help with family detection, is there a workaround for this? I only need to detect the basic Android Typefaces (SERIF, SANS-SERIF, DEFAULT, MONOSPACE etc)

推荐答案

不容易。家庭的关键是 native_instance INT ,这是包私有,不直接暴露,因为你可以见<一href=\"https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/graphics/java/android/graphics/Typeface.java\"相对=nofollow>来源$ C ​​$ C 。

Not readily. The key to the family is a native_instance int, which is package-private and is not directly exposed, as you can see in the source code.

有那个信息获取各种讨厌的方式,这可能会或可能不会在所有设备上和Android的所有过去/ present /未来的版本。

There are various nasty ways of getting at that information, which may or may not work on all devices and all past/present/future versions of Android.

也许你可以围绕字样,跟踪这些信息。

Perhaps you could create your own wrapper object around Typeface that tracks this information.

这篇关于检查Android的一个字体对象的家庭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆