Don Rhummy
Don Rhummy

Reputation: 25810

When setting a background color on a button's style, it changes the margins

If I set the background color, the margins between the buttons using this style are much smaller than without it. Why? How do I fix this?

<style name="RemoteButton">

    <!-- Leaving this in makes the buttons very close together, without it, the margins increase -->
    <item name="android:background">#d6d7d7</item>

    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:textColor">#556699</item>
    <item name="android:textSize">20dp</item>
    <item name="android:layout_margin">3dp</item>
</style>

Upvotes: 1

Views: 1351

Answers (2)

paperhs
paperhs

Reputation: 204

Add a view with other color between buttons. Or choice a picture that not fill button as a background. The reason that makes buttons very close is that you use a color as a background,then,the color will fill your button widget if without margin.

Upvotes: 0

Eli Rising
Eli Rising

Reputation: 485

The default button style is not a color, it's a drawable resource (@android:drawable/btn_default) with internal padding/margins. There is some information on it here but not much that's relevant. I would look further into android styles and how they work.

As to how to fix it, I would look here.

Upvotes: 3

Related Questions