25

I have an EditText declared as below.

<EditText 
    android:layout_margin="2dip"
    android:singleLine="true"
    android:lines="1"
    android:maxLines="1"
    android:cursorVisible="true"
    android:textCursorDrawable="@drawable/Black"
    android:textColor="@color/black"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:background="@android:drawable/editbox_background"
/>

But its not not displaying the cursor, when getting focus. When I starts typing, its showing the cursor from 1st index. I want the cursor to be displayed even in empty edittext.

I have already tried setSelection(0)but nothing happened. Please help me what should I do?

Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
  • iam having the same problem could you pls help me! – prasanthMurugan Apr 15 '16 at 07:02
  • 3
    Am I missing something here? The flagged duplicate question here is not the same at the OP. If you are here because the cursor simply isn't showing until you have at least 1 character, then check your edittext width. This will happen if it's `android:layout_width="wrap_content"`. Add some padding to make cursor visible. – veritas1 Oct 19 '16 at 16:40
  • @veritas1 Thank you very much!!! In my case extra padding changed nothing, instead I used `android:minWidth="5dp"` and it made the result. Thanks again! – duviteck Mar 29 '17 at 11:39
  • If your `EditText` is `wrap_content`, then either set `android:minWidth` (in my case 5dp didn't work, nor 10dp, but I had to do 20dp) or you can also do `android:hint=" "` (with the space, if you don't want a hint) – My House Dec 12 '19 at 19:08

1 Answers1

14

As mentioned above, here's the actual line

android:textCursorDrawable="@null"

fyi - @null didn't show up as an autocomplete option

Gene Bo
  • 11,284
  • 8
  • 90
  • 137