Android get textappearance runtime

I overridden the textview class, and I want to perform some actions when the text display is small.

How to check text display set by xml layout file?

+2
source share
1 answer

I 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, how can I check the identifier that was set as textappearance.

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

All Articles