Android button textAppearance



我可以通过在对象中设置它来改变按钮文本的外观,像这样:

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

,但在样式

中使用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>

有人知道为什么吗?

使用textAppearance定义的属性值应用于样式中的属性值之前。一个Button是一个TextView的样式应用,默认的样式按钮将覆盖你的textAppearance (Android 2.3为例,将设置为?android:attr/textAppearanceSmallInverse)和textColor

textAppearance接受样式作为值;android:textAppearance="@style/login_button_text_appearance"通常是设置textAppearance的正确方法,但不适合Button:

如果你要改变Button的文本颜色,你也应该强制使用自定义背景图像,因为如果你不这样做,一个设备将使用深色背景图像(摩托罗拉defy),另一个将使用浅色图像(htc desire),这可能会使文本难以阅读。

我认为你应该使用:

style = "@style/login_button_text_appearance"

代替:

android:textAppearance="@style/login_button_text_appearance"

android:textAppearance只是一个属性,就像任何其他属性(android:textSize, android:textStyle等)一样,样式的值不能作为该属性的值。

EDIT:

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

相关内容

最新更新