Android按钮文字外观

标签 android button styles appearance

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

<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,Button 的默认样式将覆盖您的 textAppearance(例如 Android 2.3 会将其设置为 ?android: attr/textAppearanceSmallInverse) 和 textColor

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

如果您要更改 Button 的文本颜色,您还应该强制使用自定义背景图片,因为如果不这样做,一台设备将使用深色背景图片 (motorola defy) 并且另一个将使用浅色图像 (htc desire),这可能会使文本难以阅读。

关于Android按钮文字外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8245259/

相关文章:

ios - UIToolbar 使用 Storyboard : how to change a button? 实现

android - 如何在按钮的另一种样式中使用一种样式?

android - 在工具栏中更改边距和重力折叠标题

java - 遍历泛型类

ios - iOS 中的自定义按钮,带有圆角矩形笔画、图标和标签

wpf - 使用 DataGridTextColumn 验证禁用/启用按钮

css - 无法将 div 定位在其他 div 中

css - 更改页面左侧传单标记的弹出位置?

android - 从我们的应用程序打开另一个应用程序?

java - 所有 Android 类的实际基类是什么?