如何在按钮的另一种样式中使用一种样式?

Jor*_*ort 5 android styles button

有谁知道如何将样式“MarginButton”添加到样式“bluebutton”或“OrangeButton”?我这样做的原因是为了防止重复代码,这是正确的方法还是有更好的方法来解决这个问题?

<style name="OrangeButton" parent="android:Widget.Button">
    <item name="android:textColor">#000</item>
    <item name="android:background">@drawable/roundedbutton_orange</item>
</style>

<style name="BlueButton" parent="android:Widget.Button">
    <item name="android:textColor">#FFF</item>
    <item name="android:background">@drawable/roundedbutton_blue</item>
</style>

<style name="MarginButton" parent="android:Widget.Button">
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:layout_marginLeft">3dp</item>
    <item name="android:layout_marginRight">3dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

谢谢,

乔里斯

Hos*_*kli 4

更新 将橙色按钮父级设置为@style/MarginButton。我刚刚尝试过这个并且有效

<style name="orangeButton" parent="@style/MarginButton">
    <item name="android:textColor">#000</item>
    <item name="android:background">@drawable/roundedbutton_orange</item>
</style>

<style name="MarginButton" parent="@android:style/Widget.Button">
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:layout_marginLeft">3dp</item>
    <item name="android:layout_marginRight">3dp</item>
</style> 
Run Code Online (Sandbox Code Playgroud)