【问题标题】:android get textappearance runtimeandroid获取textappearance运行时
【发布时间】:2012-01-24 08:01:20
【问题描述】:

我已经覆盖了 textview 类,我想在 textappearance 很小的时候执行一些操作。

如何查看xml布局文件设置的textappearance?

【问题讨论】:

    标签: android android-textattributes


    【解决方案1】:

    我找到了解决方法:

    private int getTextAppearance(AttributeSet attrs, int defStyle) {
        int answer = defStyle;
        for(int i=0; i<attrs.getAttributeCount(); i++) {
            if(attrs.getAttributeNameResource(i) == android.R.attr.textAppearance) {
                String attrStringValue = attrs.getAttributeValue(i);
                if(attrStringValue != null) {
                    attrStringValue = attrStringValue.replace("?", "");
                    answer = Integer.parseInt(attrStringValue);
                }
            }
        }
        return answer;
    }
    

    如果构造函数调用此函数,我可以检查已设置为 textappearance 的 id。

    if(getTextAppearance(attrs, -1) == android.R.attr.textAppearanceSmall) {}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 2012-08-07
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多