Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a style within another style for a button?

Does anyone have an idea how to add the style "MarginButton" to the style "bluebutton" or "OrangeButton"? The reason I'm doing this is to prevent double code, is this the correct way to do or are there better ways to solve this?

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

Thnx,

Joris

like image 550
Joris Vervoort Avatar asked Oct 21 '22 03:10

Joris Vervoort


1 Answers

Update Set your orange button parent to @style/MarginButton. I've just tried this and it's working,

<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> 
like image 174
Hossam Oukli Avatar answered Oct 24 '22 12:10

Hossam Oukli