Saturday, January 28, 2017

Custom EditText Cursor

Customize the cursor of an EditText is the easy way, by using xml in drawable.


Create an xml in drawable folder :

1.green_cursor.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <size
        android:width="2dip" />
    <solid
        android:color="#7119bf37" />
    <padding
        android:top="0dp"
        android:bottom="0dp" />
</shape>

2.In layout_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#e6e6e6"
    android:orientation="vertical" >
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#fff"
        android:inputType="number"
        android:maxLength="16"
        android:textCursorDrawable="@drawable/green_cursor"
        android:minWidth="40dp"
        android:textColor="#000000"
        android:textSize="17sp"
        android:textStyle="bold" />
</LinearLayout>


EmoticonEmoticon