使用样式设置按钮文本颜色

13

我无法使用预定义的样式设置按钮的文本颜色。我一定是错过了什么简单的东西。例如,我有一个按钮:

    <Button
    android:id="@+id/calculate_button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/calculate"
    android:background="@drawable/rounded_bottom_shape"
    android:padding="5dp"
    android:textAppearance="@style/CalcResultStyle">
    </Button>

相应的样式为:

<style name="CalcResultStyle">
    <item name="android:textSize">12sp</item>
    <item name="android:textColor">#FFF</item>
</style>

尺寸部分正常工作,但颜色不起作用。我找到的唯一解决方法是在实际按钮上设置textColor,这意味着更改多个按钮的颜色会变得很麻烦。我还喜欢使用颜色引用(例如@color/Brown)在我的样式中设置textColor属性,但使用引用或明确设置颜色似乎没有任何区别。


实际上,默认情况下,按钮的文本是黑色的。请仔细阅读我的问题。 - ryandlf
啊,没错,列表视图和其他项目是黑底白字。 - Jack
1个回答

15

我使用这个。也许可以帮到你。你能告诉我你在rounded_bottom_shape中写了什么吗?

<Button
android:id="@+id/calculate_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Calculate"
android:background="#454545"
android:padding="5dp"
style="@style/CalcResultStyle">
</Button>

1
奇怪...但它确实可行。我从未想过尝试删除android标记。无论如何,谢谢。 - ryandlf
2
样式会在视图层次结构中传播,而标准属性则不会。按钮没有textAppearance属性,因此它什么也不做。 - Andrew Gallasch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接