Android button textAppearance

Marek Sebera picture Marek Sebera · Nov 23, 2011 · Viewed 13.4k times · Source

I can change button text appearance by setting it right within object like this:

<Button
        android:id="@+id/login_btn_bypass"
        android:textSize="15dp"
        android:textColor="#878787"
        android:textStyle="bold" />

but not when using textAppearance within style

// in layout xml
<Button
    android:id="@+id/login_btn_login"
    android:textAppearance="@style/login_button_text_appearance" />

// in style definition 
<style name="login_button_text_appearance">
    <item name="android:textSize">15dp</item>
    <item name="android:textColor">#a7a7a7</item>
    <item name="android:textStyle">bold</item>
</style>

anyone knows why?

Answer

FunkTheMonk picture FunkTheMonk · Nov 23, 2011

The values of attributes defined using textAppearance are applied before the values of attributes in a style. A Button is a TextView with a style applied, and the default style of a Button will override your textAppearance (Android 2.3 for example will set it to ?android:attr/textAppearanceSmallInverse) and textColor.

textAppearance excepts styles as values, android:textAppearance="@style/login_button_text_appearance" is the normally correct way to set a textAppearance, but not for a Button:

If you're changing the text colour of a Button, you should also enforce a custom background image because if you don't, one device will use a dark background image (motorola defy) and another will use a light image (htc desire) which may make the text difficult to read.