Articles → ANDROID → Change The Shape Of Button In Android Application

Change The Shape Of Button In Android Application






Example




  1. Add a shape resource in drawable folder. For that
    1. Right-click on the res folder.
    2. Click on New → Android Resource File
    3. Picture showing the Android Resource File option in the context menu
      Click to Enlarge

    4. Following window will appear
    5. Picture showing a window for adding the new resource
      Click to Enlarge

    6. Change the ‘Resource Type’ to ‘Drawable’, ‘Root element’ to ‘shape’ and ‘File name’ as ‘myshape’.
    7. Click Ok.
  2. Add following code in myshape.xml.
  3. <?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>


  4. Change the button’s background to myshape
Picture showing changing the background color of the button
Click to Enlarge



Picture showing the button with the changed background color
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, November 25, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250