33

We're applying the new Android KitKat translucent theme in our apps, and we're getting a weird issue when the keyboard appears. If we don't use the new android:windowTranslucentStatus attribute, all works as usual: The screen is resized, and all remains visible. But when we're using android:windowTranslucentStatus, the screen isn't resized and our EditText becomes hidden by the keyboard.

A sample of the issue: http://fewlaps.com/xtra/quitnowStackoverflow.png

The only difference between the screens is in the attribute in the style:

First screen: <item name="android:windowTranslucentStatus">false</item>

Second screen: <item name="android:windowTranslucentStatus">true</item>

We think this is a bug from Kitkat release, but we want you to be aware of this. We're getting a little mad. Of course, if someone have a solution, it will be amazing.

EDIT: I just added this issue to the Android issue tracker. Probably you'll be interested in starring the issue: https://issuetracker.google.com/issues/36986276

Vishnu Haridas
  • 7,355
  • 3
  • 28
  • 43
Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
  • 1
    Thanks @antimo for posting the image and formatting the whole question :) – Roc Boronat Nov 11 '13 at 01:32
  • Have you tried setting the [fitsSystemWindows](http://developer.android.com/reference/android/R.attr.html#fitsSystemWindows) to true? – jush Nov 11 '13 at 06:20
  • Yes, we tried setting it in the EditText and in its container, too. But we haven't too luck. – Roc Boronat Nov 11 '13 at 10:19
  • You can try to put the `fitSystemWindows` attr in the root layout of this `Activity`. It works for me – wqycsu Jan 07 '16 at 02:21

6 Answers6

7

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!

DanielGrech
  • 1,402
  • 12
  • 16
  • Thanks @DanielGrech! I've also tryed what you mention, creating a root Layout with the fitsSystemWindows to true, and it works. But it creates another layer that the GPU has to render... We had it working for two month but... all changed when we seen the SystemBarTintManager library. It works like a charm! And also do the needed to not overstrees the GPU. Nice solution! – Roc Boronat Mar 22 '14 at 13:17
  • What if there is no layout, and the only content that is shown is of a dialog? Or when adding this will ruin the layout of the current Activity ? Look here: https://issuetracker.google.com/issues/119517990 – android developer Nov 14 '18 at 09:26
0

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.

paulgavrikov
  • 1,883
  • 3
  • 29
  • 51
  • Thanks for the approach! Right now, we decided to launch the app without the translucent layout, so it's not necessary to patch the issue. No need to hurry for a translucent top bar... :) – Roc Boronat Nov 11 '13 at 10:20
0

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

0

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).

Matt Lyons-Wood
  • 931
  • 11
  • 17
0

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

leimenghao
  • 226
  • 1
  • 10
-1

Add the following as well

<item name="android:fitsSystemWindows">true</item>
AGK
  • 189
  • 2
  • 4