leithdm
5/14/2020 - 2:54 PM

XML Drawable: shape background assigned to an EditText or a Button

//Create new Drawable Resource File in Drawable directory. 
//Root element is "shape"

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff"></solid>
    <corners android:radius="5dp"></corners>
</shape>



//assign it to e.g. an EditText
    <EditText
        android:background="@drawable/input_background"
        //...
        // ...
        //  ... />
        
************************************************************

//Example 2
//Create new Drawable Resource File in Drawable directory. 
//Root element is "shape"

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorAccent"></solid> //@color/colorAccent was defined in colors.xml
    <corners android:radius="5dp"></corners>
</shape>

/* colors.xml
<resources>
    <color name="colorPrimary">#0e96f9</color>
    <color name="colorPrimaryDark">#117cc9</color>
    <color name="colorAccent">#ffcb2b</color>
</resources>
*/

//assign it to e.g. a Button
    <Button
        android:background="@drawable/btn_background"
        //...
        // ...
        //  .../>


************************************************************

//Example 3
//Create new Drawable Resource File in Drawable directory. 
//Root element is "shape"

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:color="@color/greyColor"
        android:width="10dp"></stroke>
    <corners android:radius="5dp"></corners>
</shape>