EditText in Android doesn't show text when typing while using the on-screen keyboard

后端 未结 3 1175
温柔的废话
温柔的废话 2020-12-11 07:34

I have an activity consisting of 3 EditText fields (amongst other things like TextViews and a few buttons). I also have an AutoCompleteTextView with a list of String\'s usin

相关标签:
3条回答
  • 2020-12-11 08:10

    In fact your text is being typped, but that's a little bug that makes your text color be the same as your background, so you don't see it. This can be easily fixed by doing 2 things:

    1) Simply change the textColor of your EditText, either defining it in the layout:

    android:textColor="..."
    

    or dynamically:

    EditText et = (EditText) findViewById(R.id.your_edittext);
    et.setTextColor(Color.RED);
    

    2) Change the extended theme in your manifest:

    <application android:theme="@style/Theme.Light.NoTitleBar.Workaround" ... >
    

    3) Create the new theme at res/values/themes.xml which uses fixed styles:

    <style name="Theme.Light.NoTitleBar.Workaround" parent="@android:style/Theme.Light.NoTitleBar">
      <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewLight</item>
      <item name="android:dropDownItemStyle">@style/Widget.DropDownItemLight</item>
    </style>
    

    4) Now these styles, located at res/values/styles.xml should fix the color:

    <style name="AutoCompleteTextViewLight" parent="@android:style/Widget.AutoCompleteTextView">
      <item name="android:textColor">@android:color/primary_text_light</item>
    </style>
    <style name="Widget.DropDownItemLight" parent="@android:style/Widget.DropDownItem">
      <item name="android:textColor">@android:color/primary_text_light</item>
    </style>
    

    I know it's a mess, but try it and if it works, try finding a combination of those attributes that fit to your layout.

    0 讨论(0)
  • 2020-12-11 08:20

    It works for me may be helpful to others as well, open your manifest file and set hardwareAccelerated="true".

     <application
        android:allowBackup="true"
        .....
        android:hardwareAccelerated="true">
    

    For more about HardwareAccelerated https://developer.android.com/guide/topics/graphics/hardware-accel.html

    0 讨论(0)
  • 2020-12-11 08:34

    Ok, so I worked out what the issue was!

    The code which I didn't post because I thought it was 'irrelevant' contained a thread

    public static Runnable updateTimerMethod = new Runnable() 
    {
    
        public void run() 
        {
            sessionTimer.setText(TimerHandler.theTime);  
    
            myHandler.postDelayed(this, 0);
    
        }
     }; 
    

    I realised that the thread was basically taking up all of the activity (I don't really know how to explain that properly) by having the postDelayed as 0. Once I changed this to say... 100, then the EditText worked.

    Thank you to @NKN who helped me.

    This may be specific to me, but hopefully this will help somebody else.

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