Skip to content

Instantly share code, notes, and snippets.

@nodoid
Created February 26, 2015 21:17
Show Gist options
  • Save nodoid/c64bea9ec6d88ea20c03 to your computer and use it in GitHub Desktop.
Save nodoid/c64bea9ec6d88ea20c03 to your computer and use it in GitHub Desktop.
Styling an android button
// in Resources/drawable
// I've called this RoundedButton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />
</shape>
</item>
</selector>
// to access the button, in the axml file, add the following to a button
android:background="@drawable/RoundedButton"
// result, a nicely styled button!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment