androidandroid-edittextandroid-custom-viewandroid-4.4-kitkat

Cursor is not visible in empty custom EditText on KitKat


I have created a custom EditText class that extends android.widget.EditText. When running the app on KitKat and previous OS versions, if the custom EditText is empty, the cursor does not appear. It will appear once text is entered.

I have tried multiple solutions posted on this site including adding android:textCursorDrawable="@null" and android:textIsSelectable="true" to the XML as well as adding those properties programmatically. None of these solutions has worked.

The custom EditText does have a background I am setting, but it needs to be there. Design constraints mean that I must set a non-default background.

So the question is, how do I make the cursor appear when the custom EditText is empty?

Here is the XML for the custom view:

<?xml version="1.0" encoding="utf-8"?>
<com.example.CustomEditText
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:background="@drawable/custom_edit_text_background"
    android:gravity="start"
    android:imeOptions="actionDone"
    android:inputType="textCapSentences|textMultiLine"
    android:maxLines="5"
    android:padding="@dimen/custom_padding"
    android:textAppearance="@style/TextAppearance.AppCompat.Medium"
    android:textColor="@color/custom_color"/>

Solution

  • The solution I found is to set a minWidth on the custom EditText. A value of 40dp worked for me. Now the cursor will appear in the view, even when empty.