androidkotlinandroid-layoutandroid-drawableandroid-vectordrawable

How to make EditText and Button have this colored border?


How can make EditText with this border and Button with this border. I could not find do this with drawable. I use ImageView with this. But I can not use ImageView for EditText. How can do this?

EditText

Button


Solution

  • You can set the drawable as a background to your views. You can generate the drawable from this site, or you can use the basic drawable I created. You can modify the colors of the gradient and background color to best match your design.

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <gradient
                android:centerColor="@android:color/black"
                android:endColor="@android:color/holo_blue_light"
                android:startColor="@android:color/holo_red_light"/>
            <corners android:radius="48dp"/>
        </shape>
    </item>
    <item
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp">
        <shape android:shape="rectangle" >
            <corners android:radius="48dp"/>
            <solid android:color="@android:color/black"/>
        </shape>
    </item>
    
    </layer-list>
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text"
        android:background="@drawable/custom_background"/>
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button Text"
        android:background="@drawable/custom_background"/>
    

    Sample Output :

    Sample Output