3

In my application, I am using cursor color for EditText.

It is working in Samsung devices but in HTC One it's not showing. If I give textCursorDrawable element as null it's showing default text color as cursor color, but I need cursor color in red.

I am not able to get where is the exactly problem. Please can any one help me.

Here is my EditText in XML code:

<EditText
    android:id="@+id/username_edit"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="90"
    android:background="@null"
    android:ems="10"
    android:hint="user name"

    android:maxLength="60"
    android:paddingLeft="5dp"
    android:singleLine="true"
    android:textColor="@color/black"
    android:textCursorDrawable="@color/appheader_color"
    android:textSize="@dimen/TextSize_medium" >

</EditText>
Sufian
  • 6,405
  • 16
  • 66
  • 120
Suman Ch
  • 51
  • 2

2 Answers2

2

Try adding

android:textCursorDrawable="@null"

<EditText  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textCursorDrawable="@drawable/color_cursor"
    />

in drawable you can set your own color

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="1dp" />
    <solid android:color="#FFFFFF"  /> //#FFFFFF will be replaced by your color code
</shape>
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
  • If i add this the cursor will get visible but its showing in text color.But i required red color. – Suman Ch Nov 17 '14 at 07:37
  • refer here: https://stackoverflow.com/questions/11554078/set-textcursordrawable-programmatically – D T Jul 07 '17 at 03:11
0

Try this. It may help you.

Create drawalble xml: cursor_color

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="3dp" />
    <solid android:color="#FF0000"  />
</shape>

In Edittext :

<EditText
                    android:id="@+id/username_edit"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="90"
                    android:background="@null"
                    android:ems="10"
                    android:hint="user name"

                    android:maxLength="60"
                    android:paddingLeft="5dp"
                    android:singleLine="true"
                    android:textColor="@color/black"
                    android:textCursorDrawable="@drawable/cursor_color"
                    android:textSize="@dimen/TextSize_medium" >


                </EditText>
Remees M Syde
  • 2,564
  • 1
  • 19
  • 42