How to set EditText inside blinking cursor color using android:textCursorDrawable attribute.
EditText cursor is the blinking slim vertical line display inside EditText which tells the app user that EditText is now selected and you can write your text here. EditText cursor can be easily changeable through android:textCursorDrawable=”@null” attribute and after that you have to define android:textColor=” “ attribute and it will automatically get the text color as cursor color. So here is the completes step by step tutorial for Change EditText cursor color in android programmatically.
How to Change EditText cursor color in android programmatically.
Code for MainActivity.java file.
package com.changeedittextcursor_android_examples.com; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
Code for activity_main.xml layout file.
<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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.changeedittextcursor_android_examples.com.MainActivity" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textCursorDrawable="@null" android:textColor="#fe0101" android:gravity="center" android:hint="EditText Cursor Change" > </EditText> </RelativeLayout>
Screenshot: