Pedram Yazdipour
Pedram Yazdipour

Reputation: 59

Customizing color of default cursor mover in android

In addition to cursor which is like a short line, there is another thing that when user click on the edittext appears and by moving that cursor will move to edit a text . I donot know what is its name (Im not native in English) so I cant customize its color .This is blue for google chrome for instance and by this thing you can pass through every character of text. Can anyone help me with this element of edittext please ? Tnx in advance .enter image description here

Upvotes: 3

Views: 1619

Answers (3)

Shubhank Gupta
Shubhank Gupta

Reputation: 863

Above both the answer is correct if you want to change the color of the cursor

android:textCursorDrawable="@null"
android:textColor="Color"

you can also do that using the java

Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
f.setAccessible(true);
f.set(yourEditText, R.drawable.cursor);

But if you want to change the position as you mention in comment use that

editText.setSelection(position) 

Change the color of the pointer

In your styles.xml put like this:

<item name="colorAccent">@color/blue</item>

Some link you may refer Change mouse cursor image in application?

you may also refer that http://www.pocketmagic.net/android-overlay-cursor/#.UmjDQpAW0kc

Upvotes: 0

Satan Pandeya
Satan Pandeya

Reputation: 3815

You can customize that pointer from your style:

<style name="CustomEditTextView" parent="TextAppearance.AppCompat">
<item name="colorAccent">@color/your_prefer_color</item>       
</style>

Include this style in EditText:

android:theme="@style/CustomEditTextView"

Upvotes: 1

Suraj Makhija
Suraj Makhija

Reputation: 1396

First of all, you can create a shape drawable named drawable_cursor_white ( for white cursor ) as follows :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:width="1dp" />
    <corners android:radius="1dp" />
    <solid android:color="@android:color/white" />
</shape>

Thereafter, just use attribute textCursorDrawable as follows in the EditText as follows :

<EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"  
                android:textCursorDrawable="@drawable/drawable_cursor_white" />

Or else, if you want to apply the custom cursor everywhere in your application, then you can create a theme and apply it wherever you want.

Upvotes: 0

Related Questions