Reputation: 3958
I need to create a layout like below.
And I worked out how to create a this layout:
How can I add top and bottom margins? And button background color? I made the button transparent by using:
android:background="@android:color/transparent"
Now how can I make button background color to light blue.
If I use custom button layout, how can I do that? I checked lots of Stackoverflow questions, but all of them concern gradient, color change on click, etc.
Thank you!
Upvotes: 0
Views: 1267
Reputation: 102793
You don't want to use the transparent background color ... instead set it to the blue color you want. Then use setAlpha to make it partially transparent:
MyButton.getBackground().setAlpha(50);
To set both the border and transparent background, I think you'll have to make an XML drawable and define as the button's background:
android:background="@drawable/mybuttonbackground"
Then the drawable resource should be like this (/res/drawable/mybuttonbackground.xml):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#FF000000" />
<solid android:color="#FFFFFF" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape ="rectangle">
<stroke android:width="1dp" android:color="#FFDDDDDD" />
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
Upvotes: 1