【问题标题】:Android style inheritance not workingAndroid风格继承不起作用
【发布时间】:2015-03-28 17:31:53
【问题描述】:

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"/>

此按钮仅将“大”和“点画”属性设置为“红色”。为什么?

【问题讨论】:

    标签: android inheritance styles


    【解决方案1】:

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

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

    【讨论】:

    • 不建议将parent属性和点表示法混用。无论如何,parent 总是覆盖点符号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 2013-04-30
    • 2013-07-11
    • 2020-01-17
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多