Articles → ANDROID → Change The Shape Of Button In Android Application
Change The Shape Of Button In Android Application
Example
- Add a shape resource in drawable folder. For that
- Right-click on the res folder.
- Click on New → Android Resource File
Click to Enlarge
- Following window will appear
Click to Enlarge
- Change the ‘Resource Type’ to ‘Drawable’, ‘Root element’ to ‘shape’ and ‘File name’ as ‘myshape’.
- Click Ok.
- Add following code in myshape.xml.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:color="#ff0000"></stroke>
<gradient android:endColor="@color/design_default_color_primary"
android:startColor="@color/colorPrimaryDark" android:angle="90"></gradient>
</shape>
- Change the button’s background to myshape
Click to Enlarge
Click to Enlarge