Android风格继承不起作用

时间:2015-03-28 17:31:53

标签: android inheritance styles

styles.xml

    <style name="Red" parent="android:TextAppearance.DeviceDefault.Medium.Inverse">
        <item name="android:textColor">#f00</item>
    </style>

    <style name="Red.LARGE">
        <item name="android:textSize">30sp</item>
    </style>

当我使用它时

<Button
    android:id="@+id/save"
    android:text="@string/save"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/save_marginTop"
    android:gravity="center"
    style="@style/Red.LARGE"/>

此按钮属性仅限大型和doest绘制为红色。为什么?

1 个答案:

答案 0 :(得分:1)

您的Red.LARGE样式需要使用parent属性。如果将Red更改为:

,Red.LARGE将继承Red
<style name="Red.LARGE" parent="Red">
    <item name="android:textSize">30sp</item>
</style>