EditText cursor is invisible in Android 4.0

前端 未结 11 1230
逝去的感伤
逝去的感伤 2020-12-14 09:16

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?

相关标签:
11条回答
  • 2020-12-14 09:24

    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

    0 讨论(0)
  • 2020-12-14 09:25

    Make android:cursorVisible="true"

    and

    If you have used android:textColor then set the android:textCursorDrawable attribute to @null.

    Happy coding ;)

    0 讨论(0)
  • 2020-12-14 09:25

    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" />
    
    0 讨论(0)
  • 2020-12-14 09:27

    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.

    0 讨论(0)
  • 2020-12-14 09:32

    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"
        />
    
    0 讨论(0)
  • 2020-12-14 09:36

    Add this line for your edit text in the xml file.

    android:textCursorDrawable="@null"
    
    0 讨论(0)
提交回复
热议问题