Shishir Gupta
Shishir Gupta

Reputation: 1582

Android - set padding color via XML/Java

I want to add a padding of color #fff (white) around a button with background #000 (black). When I set it with

   <Button
       android:background="#000"
       android:padding="20dp"
    />

What happens is that padding is invisible (as it's black colored).

Basically I've a linearlayout (with weightsum="5") and 5 buttons under it with equal weights ("1" for each). I want buttons distinctly visible as in to be visible as put individually over the white background!

Upvotes: 2

Views: 5705

Answers (1)

asannov
asannov

Reputation: 189

if you want the padding in your buttons you can use shapes as background

create an xml file in res/drawable folder and set it as button background

file content is something like this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid
            android:color="#333"/>
    </shape>
</item>
<item android:left="20dp" android:right="20dp" android:top="20dp" android:bottom="20dp">
    <shape android:shape="rectangle">
        <solid
            android:color="#fff"/>
    </shape>
</item>
</layer-list>

else you can set linearlayout's background "#fff" and use margins for buttons

Upvotes: 2

Related Questions