textColor以样式定义,未应用于按钮文本

时间:2012-06-18 12:37:58

标签: java android button colors styles

我的应用程序中有几个按钮,我想将样式应用于所有这些按钮。

以下是我放在我的values文件夹中的styles.xml文件。

<?xml version="1.0" encoding="utf-8"?>

 <resources>

     <style name="buttonStyle">
      <item name="android:textStyle"> bold </item>
      <item name="android:textColor"> #282780 </item>
      <item name="android:textSize"> 20sp </item>
     </style>

</resources>

在我的布局xml文件中,我使用按钮中的样式,如下所示,

<Button android:id="@+id/ok_preview_appointment_button" 
        android:text="@string/ok_preview_appointment_button"
        android:layout_width="175dp"
        android:layout_height="35dp"
        android:layout_marginBottom="10dp"
        style="@style/buttonStyle"
        android:background="@drawable/button_background" />

我收到以下错误“java.lang.NumberFormatException:颜色值'#282780'必须以#开头”

我检查了其他线程,但是当他们使用@color时他们似乎都遇到了这个问题,这不是我的情况。

提前谢谢!

1 个答案:

答案 0 :(得分:5)

你给了以下风格的空间: <item name="android:textColor"> #282780 </item>。 删除后尝试。我不确定,但其他一切看起来都很好,这可能就是问题所在。