【发布时间】:2012-01-24 08:01:20
【问题描述】:
我已经覆盖了 textview 类,我想在 textappearance 很小的时候执行一些操作。
如何查看xml布局文件设置的textappearance?
【问题讨论】:
标签: android android-textattributes
我已经覆盖了 textview 类,我想在 textappearance 很小的时候执行一些操作。
如何查看xml布局文件设置的textappearance?
【问题讨论】:
标签: android android-textattributes
我找到了解决方法:
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) {}
【讨论】: