Android - customize edittext style

This code focus on EditText Style Customization, with normal, focussed and pressed style. When you develop an application for TV, it is very important. Because in TV, we use the Remote Control (Dpad) to move and choose items.

- Create the drawable/bg_edittext.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"><shape android:shape="rectangle">
            <solid android:color="#33000000"/>
            <stroke android:width="3dp" android:color="#ff7d1d85"/>
            <corners android:radius="20dp" />
            <padding android:bottom="7dp" android:left="15dp" android:right="10dp" android:top="6dp" />
        </shape></item>
    <item android:state_focused="true"><shape>
            <solid android:color="#33000000"/>
            <stroke android:width="3dp" android:color="#ff7d1d85" />
            <corners android:radius="20dp" />
            <padding android:bottom="7dp" android:left="15dp" android:right="10dp" android:top="6dp" />
        </shape></item>

    <item><shape>
            <solid android:color="#00000000"/>
            <stroke android:width="1dp" android:color="#ff7d1d85" />
            <corners android:radius="20dp" />
            <padding android:bottom="7dp" android:left="15dp" android:right="10dp" android:top="6dp" />
        </shape></item>
</selector>


- Then, define an edittext view with the bg_edittext style:
        <EditText
            android:id="@+id/edittextUsername"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_edittext"
            android:text=""
            android:hint=""
            android:textColor="@color/white"
            android:layout_marginTop="10dp"
            />
 

Leave a Reply

Powered by Blogger.