用样式设置按钮文本颜色

rya*_*dlf 13 xml android styles textcolor

我无法使用预定义的样式设置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>
Run Code Online (Sandbox Code Playgroud)

相应的风格是:

<style name="CalcResultStyle">
    <item name="android:textSize">12sp</item>
    <item name="android:textColor">#FFF</item>
</style>
Run Code Online (Sandbox Code Playgroud)

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

kal*_*a c 14

我用这个.也许它会帮助你.你能告诉我你在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>
Run Code Online (Sandbox Code Playgroud)

  • 样式通过视图层次结构传播,标准属性不会。Button 没有 textAppearance 属性,因此它什么都不做。 (2认同)