Keyboard hiding EditText when android:windowTranslucentStatus=true

馋奶兔 提交于 2019-11-28 20:11:27

I also ran into this very annoying issue. But eventually I got this working:

<style name="Theme.MyApp">
    <item name="android:windowTranslucentStatus">true</item>
</style>

Instead of setting fitSystemWindows="true" in the theme, I set it on the root view of my layout..

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</FrameLayout>

I also use the great SystemBarTintManager in my activity:

new SystemBarTintManager(this).setStatusBarTintEnabled(true);

This seems to work well, but admittedly seems pretty fickle. Hope it helps someone anyway!

A workaround would be:

Add a Touch or Focus or ClickListener and move up the EditText holding layout up to half of the screen. However this is really not the way it should work, so keep your fingers crossed and hope that Google gets it fixed.

EditText e = new EditText(this);
    e.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus)
                v.animate().x(screenHeight/2f).start();
            else
                v.animate().x(screenHeight).start();
        }
    });

Just adjust v to your holding layout and make sure the positions you move to look good.

put this below lines after oncreate in you activity

    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Window window = this.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(mCategoryColors.getColorStatusBar());
    }

Work for me :)

This isn't a perfect solution but a workaround I found was to set android:windowSoftInputMode="adjustPan" in AndroidManifest.xml.

Note that this will pan the whole window out of the way of the keyboard, rather than resizing it.

More info here (search for windowSoftInputMode).

set android:windowSoftInputMode="adjustPan" in AndroidManifest.xml is ok. But i just want to say that it not work when activity is FullScreen, for more details see Android How to adjust layout in Full Screen Mode when softkeyboard is visible

Add the following as well

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