Android按钮textAppearance

Mar*_*era 8 android styles appearance button

我可以通过在对象内设置它来更改按钮文本外观,如下所示:

<Button
        android:id="@+id/login_btn_bypass"
        android:textSize="15dp"
        android:textColor="#878787"
        android:textStyle="bold" />
Run Code Online (Sandbox Code Playgroud)

但在样式中使用textAppearance时却没有

// 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>
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么?

Fun*_*onk 13

使用textAppearance定义的属性值将应用于样式中属性的值之前.一个ButtonTextView应用了风格,按钮的默认样式将覆盖textAppearance(Android 2.3的例如将其设置到Android:ATTR/textAppearanceSmallInverse)和文字颜色.

textAppearance将样式android:textAppearance="@style/login_button_text_appearance"排除为值,是设置textAppearance的常用方法,但不适用于Button:

如果您要改变的文本颜色Button,你也应该执行自定义背景图片,因为如果不这样做,一个设备将使用的是深色的背景图像(摩托罗拉Defy),另一个将使用光图像(HTC Desire的),这可能使文本难以阅读.


Hou*_*ine 9

我认为你应该使用:

android:textAppearance

代替

android:textSize

android:textStyle只是一个属于任何其他属性(android:textAppearance...等)的属性,并且该风格的价值不被接受作为该属性的值

编辑:

style = "@style/login_button_text_appearance"
Run Code Online (Sandbox Code Playgroud)