PrefUtil.java 文件源码

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

项目:GitHub 作者:
static void setLayoutResource(@NonNull Context context, @NonNull Preference preference, @Nullable AttributeSet attrs) {
    boolean foundLayout = false;
    if (attrs != null) {
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            final String namespace = ((XmlResourceParser) attrs).getAttributeNamespace(0);
            if (namespace.equals("http://schemas.android.com/apk/res/android") &&
                    attrs.getAttributeName(i).equals("layout")) {
                foundLayout = true;
                break;
            }
        }
    }

    boolean useStockLayout = false;
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Preference, 0, 0);
        try {
            useStockLayout = a.getBoolean(R.styleable.Preference_useStockLayout, false);
        } finally {
            a.recycle();
        }
    }

    if (!foundLayout && !useStockLayout)
        preference.setLayoutResource(R.layout.md_preference_custom);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号