Android textAppearance button

I can change the appearance of the button by setting it directly inside the object as follows:

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

but not when using textAppearance in 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> 

who knows why?

+6
source share
2 answers

I think you should use:

style = "@style/login_button_text_appearance"

instead

android:textAppearance="@style/login_button_text_appearance"

android:textAppearance is just an attribute, like any other attribute ( android:textSize,android:textStyle ... etc.), and the style value is not acceptable as the value for the attribute

EDIT:

 <Button android:id="@+id/login_btn_login" style="@style/login_button_text_appearance" /> 
+9
source

Attribute values ​​defined using textAppearance apply before attribute values ​​in a style. A Button is a TextView with a style, and the default Button style will override your textAppearance (for example, Android 2.3 will set it to: android: attr / textAppearanceSmallInverse) and textColor.

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

If you change the color of the Button text, you must also force the custom background image, because if you do not, one device will use a dark background image (motorola defy) and the other will use light image (htc desire), which may make it difficult to read text.

+11
source

Source: https://habr.com/ru/post/902222/


All Articles