Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add border to EditText in android

edittext pic

Hi, I want to add an textbox just like the image above in android app. I used the edittext control,but cannot show border.

like image 644
Ryan Sun Avatar asked Jun 18 '17 07:06

Ryan Sun


1 Answers

Create a new xml file edit_text_border.xml in drawable folder, or give name of your choice. Then add the following code:

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid
        android:color="@android:color/transparent"/>

    <corners
        android:bottomRightRadius="12dp"
        android:bottomLeftRadius="12dp"
        android:topLeftRadius="12dp"
        android:topRightRadius="12dp"/>
    <stroke
        android:color="#ffffff"
        android:width="1dp"/>
</shape>

You can adjust the stroke color and radius values to your requirements. Finally, in your edittext set it as background like following.

<EditText
    android:id="@+id/edit_text"
    android:background="@drawable/edit_text_border"/>
like image 176
Subhan Ali Avatar answered Sep 22 '22 11:09

Subhan Ali