设置按钮的文字颜色与样式 [英] Setting Button Text Color with a Style
问题描述
我一直无法设置使用predefined风格按钮的文本颜色。我一定是失去了一些东西简单。例如,我有一个按钮:
I have not been able to set the text color of a Button using a predefined style. I must be missing something simple. For example, I have a button:
<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>
尺寸部分工作正常,但颜色不。我发现的唯一的解决方法是设置文字颜色上的实际按钮,这意味着在一些按键改变颜色变成一种痛苦。我也preFER使用一种颜色的参考,如@色/棕色的例子,但使用的是基准设置颜色或明确似乎没有区别设置在我的风格的文字颜色属性。
The size portion works fine, but the color does not. The only workaround I have found is to set the textColor on the actual button, which means changing colors on a number of buttons becomes a pain. I also prefer to set the textColor attribute in my styles using a color reference such as @color/Brown for example, but setting the color using a reference or explicitly seems to make no difference.
推荐答案
我用这个。也许这会帮助你。你能告诉我你在rounded_bottom_shape写的是什么?
I use this. Maybe it will help you. Can you please tell me what you wrote in 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>
这篇关于设置按钮的文字颜色与样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!