TextAppearance.java 文件源码

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

项目:android_ui 作者:
/**
 * Set ups this text appearance holder with text appearance values from the specified <var>resId</var>
 * style.
 *
 * @param context Context used to parse text appearance attributes from the specified style resource.
 * @param resId   Resource id of the desired TextAppearance style from which to parse attributes.
 * @return {@code True} if some of attributes of this text appearance has changed, {@code false}
 * otherwise.
 */
public boolean fromStyle(@NonNull Context context, @StyleRes int resId) {
    this.reset();
    final TypedArray typedArray = context.obtainStyledAttributes(resId, R.styleable.Ui_TextAppearance);
    if (typedArray != null) {
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_TextAppearance_android_textSize) {
                this.mTextSize = typedArray.getDimensionPixelSize(index, (int) mTextSize);
            } else if (index == R.styleable.Ui_TextAppearance_android_textColor) {
                this.mTextColors = typedArray.getColorStateList(index);
            } else if (index == R.styleable.Ui_TextAppearance_android_textStyle) {
                this.mTextStyle = typedArray.getInt(index, mTextStyle);
            } else if (index == R.styleable.Ui_TextAppearance_android_typeface) {
                this.mTypefaceIndex = typedArray.getInt(index, mTypefaceIndex);
            } else if (index == R.styleable.Ui_TextAppearance_android_fontFamily) {
                this.mFontFamily = typedArray.getString(index);
            } else if (index == R.styleable.Ui_TextAppearance_uiFont) {
                final String fontPath = typedArray.getString(index);
                if (!TextUtils.isEmpty(fontPath)) {
                    this.mTypeface = Font.create(fontPath).getTypeface(context);
                }
            }
        }
        typedArray.recycle();
        return n > 0;
    }
    return false;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号