android get textappearance runtime
Asked Answered
E

1

2

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?

Extravagance answered 24/1, 2012 at 8:1 Comment(0)
E
4

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) {}
Extravagance answered 25/1, 2012 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.