【问题标题】:textColor defined in style not being applied to button text样式中定义的 textColor 未应用于按钮文本
【发布时间】:2012-06-20 10:27:14
【问题描述】:

我的应用程序中有几个按钮,我想为所有按钮应用一种样式。

以下是我放在 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: Color value '#282780' must start with #”

我检查了其他线程,但他们似乎都在使用 @color 时遇到了这个问题,而我的情况并非如此。

提前感谢您!

【问题讨论】:

  • 你在样式中给出了空间,例如: #282780 。删除后尝试。我不确定,但其他一切看起来都很好,所以这可能是问题所在。
  • 你说得对!能否请您单独发布您的答案,以便我标记它。谢谢一百万!

标签: java android button colors styles


【解决方案1】:

您在样式中给出了空间,例如: &lt;item name="android:textColor"&gt; #282780 &lt;/item&gt;。 删除后试试。我不确定,但其他一切看起来都很好,所以这可能是问题所在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多