CalligraphyUtils.java 文件源码

java
阅读 38 收藏 0 点赞 0 评论 0

项目:DownloadableCalligraphy 作者:
/**
 * Tries to pull the Font Path from the View Style as this is the next decendent after being
 * defined in the View's xml.
 *
 * @param context     Activity Activity Context
 * @param attrs       View Attributes
 * @param attributeId if -1 returns null.
 * @return null if attribute is not defined or found in the Style
 */
@FontRes
static int pullFontPathFromStyle(Context context, AttributeSet attrs, int[] attributeId) {
    if (attributeId == null || attrs == null)
        return 0;
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, attributeId);
    if (typedArray != null) {
        try {
            // First defined attribute
            int fontFromAttribute = typedArray.getResourceId(0, 0);
            if (fontFromAttribute != 0) {
                return fontFromAttribute;
            }
        } catch (Exception ignore) {
            // Failed for some reason.
        } finally {
            typedArray.recycle();
        }
    }
    return 0;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号