EditText cursor is invisible in Android 4.0

前端 未结 11 1231
逝去的感伤
逝去的感伤 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:36

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

    android:cursorVisible="true"
    
    0 讨论(0)
  • 2020-12-14 09:46

    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.

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

    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.

    0 讨论(0)
  • 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.

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

    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"

    0 讨论(0)
提交回复
热议问题