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

孤街醉人 提交于 2019-11-28 12:35:31

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!