【问题标题】:Android button textAppearanceAndroid按钮文字外观
【发布时间】:2012-01-04 22:13:49
【问题描述】:

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

<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>

有人知道为什么吗?

【问题讨论】:

    标签: android button styles appearance


    【解决方案1】:

    使用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 的愿望),这可能会使文本难以阅读。

    【讨论】:

      【解决方案2】:

      我认为你应该使用:

      style = "@style/login_button_text_appearance"
      

      代替:

      android:textAppearance="@style/login_button_text_appearance"
      

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

      编辑:

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

      【讨论】:

      • 我在 Button 上没有看到任何 android:style,我应该如何应用您的建议?
      • 没有属性名为 android:style ,直接命名为 style ,看我的编辑
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多