Customizing EditText

May 26, 2014




Under res folder create new folder called drawable .
Under drawable folder create new XML file called box_edittext

Under box_edittext.xml file include following code
box_edittext.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >

    <solid android:color="#FFFFFF" />

    <corners
        android:bottomLeftRadius="5dp"
        android:bottomRightRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp" />

</shape>


Whenever you want to customize the EditText just call background property and call box_edittext from drawable folder as follows
activity_main.xml:
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#cccccc" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:background="@drawable/box_edittext"
        android:ems="10"
        android:hint="enter name"
        android:inputType="textPersonName"
        android:paddingLeft="5dp" >

        <requestFocus />
    </EditText>

</RelativeLayou



Artikel Terkait

Previous
Next Post »