I have an EditText
input in Android 4.0 and the Cursor is not showing inside it.
What can make the cursor not appear in the input field?
If the EditText has a Background drawable with a border, the cursor is displaying in the border and appears to be invisible. To rectify the problem set padding in the EditText to a small amount e.g. 5dp
Make android:cursorVisible="true"
and
If you have used android:textColor
then set the android:textCursorDrawable
attribute to @null
.
Happy coding ;)
As mentioned above, here's the actual line
android:textCursorDrawable="@null"
<EditText
android:textCursorDrawable="@null"
android:imeOptions="actionNext"
android:id="@+id/edSMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_corner"
android:inputType="phone" />
My issue was that I was using the AppCompat theme, but I had some custom view classes that extended EditText that needed to extend AppCompatEditText in order for the AppCompat style to be applied correctly.
In My case the cursor is visible if user language is English but if he change his language to Arabic then its not visible.
To fix this I have created on custom drawable for cursor.
Cursur shap at drawable/black_cursor.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#a8a8a8"/><!-- This is the exact color of android edit text Hint -->
<size android:width="1dp" />
</shape>
Edit Text:
<EditText
android:id="@+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textCursorDrawable="@drawable/black_cursor"
/>
Add this line for your edit text in the xml file.
android:textCursorDrawable="@null"