Create a custom button bar

I need to create a custom button bar control in Android, for example here . To create such a button bar, I am going to expand LinearLayout and add my own buttons to it. The buttons have a black background, but with a gradient fill; I do not want to use PNG, since the color of the buttons may change at runtime.

How can I get a similar effect in Android?

Thanks.

+2
android
source share
1 answer

u should use the image view function as a button.

set two images, you can change the color of the button

use xml file for src of this image e.g.

<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="@drawable/back_normal" /> <item android:state_pressed="true" android:drawable="@drawable/back_pressed" /> </selector> 

for gredient style.

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="90" android:startColor="#663300" android:centerColor="#330000" android:endColor="#330000"/> </shape> 

thats it.

+4
source share

All Articles