I created some custom button styles. All of the styling items are applied to buttons in the Activity that uses this style, except for layout_margin_top
. I don't really understand what is different about this item, so if someone could let me know why, that would be awesome. Attached are two images. The incorrect image with no margin between buttons was rendered with layout_marginTop="4dp"
on the style, and the correct image with margin between buttons was rendered with layout_marginTop="4dp"
on each button in the layout.
What I tried
My ideal style.
<style name="ButtonStyle" parent="@android:style/Widget.Button">
<item name="android:textColor">@android:color/white</item>
<item name="android:background">@drawable/button</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:textSize">@dimen/text_medium_small</item>
<item name="android:layout_marginTop">4dp</item>
</style>
My buttons inside a LinearLayout:
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:onClick="logSignificantEvent"
android:text="@string/button_trigger_event"/>
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:onClick="logDay"
android:text="@string/button_subtract_a_day"/>
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:onClick="showChoice"
android:text="@string/button_force_choice"/>
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:onClick="showRating"
android:text="@string/button_force_rating"/>
What worked
Style without margin.
<style name="ButtonStyle" parent="@android:style/Widget.Button">
<item name="android:textColor">@android:color/white</item>
<item name="android:background">@drawable/button</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:textSize">@dimen/text_medium_small</item>
</style>
I had to apply margins directly to every button.
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_marginTop="4dp"
android:onClick="logSignificantEvent"
android:text="@string/button_trigger_event"/>
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_marginTop="4dp"
android:onClick="logDay"
android:text="@string/button_subtract_a_day"/>
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_marginTop="4dp"
android:onClick="showChoice"
android:text="@string/button_force_choice"/>
<Button android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_marginTop="4dp"
android:onClick="showRating"
android:text="@string/button_force_rating"/>
For reference, here is the theme I am using on this Activity:
<style name="MyTheme" parent="android:Theme.Holo.NoActionBar">
<item name="android:buttonStyle">@style/ButtonStyle</item>
</style>