EditText shows the status bar, or causes content above to move instead of resize

3.9k views Asked by At

Background

I have a login Activity , which has a layout as such (vertically, from top to bottom) :

  1. title (logo ImageView and TextView)
  2. image&viewPager that takes the rest of the screen
  3. EditTexts&login button, appear on top of #2 (covering a part of them), but at the bottom of the screen

I need to have this activity full screen, hiding the status bar, and when the soft keyboard appears, change the layout a bit for what's shown above #3 .

The problem

It seems that the combination of those requirements are quite problematic.

I have 2 main issues with them:

  • What I've made for sensing the soft-keyboard being shown- doesn't seem to work here even though it worked fine on other Activities.

  • When the soft-keyboard appears, it either re-shows the status bar, or it moves the content above the bottom area (#3) instead of resizing it, while also hiding the button at the bottom (of #3) and showing only the EditText as the first view above the soft-keyboard.

Since there is no way to really have a listener for when the soft-keyboard is shown/hidden, I had to create a customized layout that just tells me when its size has changed. When its height is reduced, I assume the keyboard is shown, and vice versa.

What I've tried

  • I've tried multiple variants of the layout. Doesn't seem to help
  • I've used this layout as the root of the fragment, to check if the soft-keyboard is shown (as it changes its size) : https://stackoverflow.com/a/25895869/878126 Sadly, it works on all other activities except for this one.
  • I've tried various "windowSoftInputMode" values, including "adjustResize" and "adjustPan"
  • I thought the issues were because I use a transparent navigation bar, so I've disabled it and also disabled "fitsSystemWindows" for the bottom area (#3) .
  • I've tried this way to hide the status bar:

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    and also this way:

    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    } else
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    

The current layout

here's a short description of the current layout:

<LayoutSizeChangedSensorFrameLayout>
 <RelativeLayout>

   #1
   <LinearLayout vertical, aligned to parent-top>
    <ImageView/>
    <TextView/>
    <CirclePageIndicator/>
   </LinearLayout>

   #2
   <ImageView aligned to parent-bottom, and below #1 />
   <ViewPager aligned to the ImageView from all sides/>

   #3
   <LinearLayout vertical, aligned to the parent-bottom>
    <TextView/>
    <EditText/>
    <Button/>
    </LinearLayout>

 </RelativeLayout>
</LayoutSizeChangedSensorFrameLayout>

And this is the theme of the activity:

<style name="AppTheme.Material" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentNavigation" tools:ignore="NewApi">true</item>
    <item name="android:windowTranslucentStatus" tools:ignore="NewApi">true</item>
    <item name="android:navigationBarColor" tools:ignore="NewApi">@android:color/transparent</item>
</style>

The question

How come hiding the status bar doesn't work permanantly, or it affects what's shown when showing the soft-keyboard ?

How come my customized layout can't sense that the soft-keyboard is shown?

Are there any other ways to achieve what I've tried?

2

There are 2 answers

0
Aditya On

In addition to adding FLAG_FULLSCREEN to window, FLAG_FORCE_NOT_FULLSCREEN - this flag can also be cleared:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

2
buron On

I managed to keep the status bar hidden when the soft keyboard shows, by doing the following 2 steps:

  1. Adding the following in the onCreate of the activity:

    //No title bar is set for the activity
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    //Full screen is set for the Window  
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
  2. Setting windowFullscreento truein the theme:

    <style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowFullscreen">true</item>
    </style>
    

Unfortunately this is not a complete answer, but it might help you get some of the way.