android get textappearance runtime

眉间皱痕 提交于 2019-12-10 11:05:10

问题


I have overriden the textview class and I want to perform some things when the textappearance is small.

How do I check the textappearance that has been set by the xml layout file?


回答1:


i have found a workaround:

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;
}

if the constructor calls this function than i can check the id that has been set as textappearance.

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


来源:https://stackoverflow.com/questions/8983629/android-get-textappearance-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!