Search code examples
androidandroid-edittextcursor-position

edittext cursor is not visible when width is wrap content


I have edit text width background drawable and its width is wrap content. When I changed widht wrap to match parent then the cursor will visible.

I have tried android:textCursorDrawable="@null" and editext .setRawInputType(InputType.TYPE_CLASS_TEXT); but it is not working for me.

Note: Background color will change dynamically

Editext code:

<EditText
        android:id="@+id/edt_input"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/rounded_border_text_view"
        android:gravity="center"
        android:inputType="textMultiLine"
        android:maxLength="75"
        android:padding="@dimen/dp_08"
        android:textColor="@color/white"
        android:textSize="@dimen/sp_30"> <requestFocus /> </EditText>

rounded_border_text_view.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
    android:width="@dimen/dp_02"
    android:color="@color/color_00000000" />
<solid android:color="@color/transparent_totally" />

<padding
    android:bottom="@dimen/dp_05"
    android:left="@dimen/dp_05"
    android:right="@dimen/dp_05"
    android:top="@dimen/dp_05" />

<corners android:radius="@dimen/dp_05" />


Solution

  • When using wrap_content there is a risk the component is just too small for you to see it.

    In that case you could set a min width ? Using styles would be a good practice if you have several components in that case.