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:47

I had a similar problem but it was because the cursor is actually white and I had a white background. I needed to be able to change the cursor to black in code somehow and used this approach.

I created a layout resource called textbox.axml which contained this

   <?xml version="1.0" encoding="utf-8"?>
   <EditText xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="This is a template"
    android:background="#ffffff"
    android:textColor="#000000"
    android:cursorVisible="true"
    android:textCursorDrawable="@null" />

I then applied this layout in code (C# because I am using Xamarin) thus

    EditText txtCompletionDate = (EditText)LayoutInflater.Inflate(Resource.Layout.textbox, null);

but it is similar in Java.

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

I happened quite same problem - cursor was showing up only after user types some characters. I tried solutions listed here, but without any success on my device. What actually work for me, is setting blank text to my edittext:

EditText editText = findViewById(R.id.edit_text);
editText.setText("");

This "fakes" the user input, and cursor appears.

查看更多
在下西门庆
4楼-- · 2019-01-22 13:52

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

android:cursorVisible="true"
查看更多
甜甜的少女心
5楼-- · 2019-01-22 13:57

Make android:cursorVisible="true"

and

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

Happy coding ;)

查看更多
登录 后发表回答