android get textappearance runtime

可紊 提交于 2019-12-06 11:19:46

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