Edittext cursor is invisible in android 4.0

2019-01-22 12:53发布

I have an edit-text input in android 4.0 and the Cursor is not showing inside it.

What can make the cursor not appear in the input field?

10条回答
我命由我不由天
2楼-- · 2019-01-22 13:31

Just adding my own personal fix to anyone it might help. I had tried everything here but forcing android:background="@null" was causing a very tiny cursor only at the end of my right aligned TextEdit (it was right working fine elsewhere).

Simply adding android:padding="1dp" in my TextEdit solved the issue.

查看更多
相关推荐>>
3楼-- · 2019-01-22 13:32

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.

查看更多
看我几分像从前
4楼-- · 2019-01-22 13:33

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" />
查看更多
放我归山
5楼-- · 2019-01-22 13:40

I found what was causing it to happen to me.

You need to inherit it from the application's theme. I'm not sure what the line item needs to be exactly, but android:Theme has it so inheriting that will do that trick.

Using the default AppBaseTheme will work (it has android:Theme.Light as it's parent).

To use AppBaseTheme put android:theme="@style/AppBaseTheme" into your application tag in the manifest. You can also use a custom style and multiple levels of inheritance so long as one of them has parent="android:Theme" in the style tag.Like I said it may be possible to have it without that, just using certain line item(s) but I don't know what those would be.

If you don't need a custom theme you can just use

android:theme="@android:style/Theme"

查看更多
干净又极端
6楼-- · 2019-01-22 13:43

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

android:textCursorDrawable="@null"
查看更多
时光不老,我们不散
7楼-- · 2019-01-22 13:43

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"
    />
查看更多
登录 后发表回答