8

I am having an issue with the keyboard. When it disappears, the space it occupied remains blank and the rest of the layout does not adjust

normal screen:

enter image description here

with keyboard:

enter image description here

keyboard dismissed:

enter image description here

I have never seen this before, so I am not even sure where to start looking. This happens on 4.2.2 as well as 5.1

The other piece of important information is that this is a custom LinearLayout that holds all of the content. Maybe it has something to do with that. I can upload any code if necessary.

This is the main layout file shell.

<com.edgetechlabs.app_v2.MasterLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Menu (Drawer)-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:visibility="visible"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     <ScrollView
        android:id="@+id/activity_main_menu_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/drawer_background"
        android:cacheColorHint="#00000000" >
     </ScrollView>
</LinearLayout>
<!-- Fragment Holder -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!-- This is where fragment will show up -->
    <FrameLayout
        android:id="@+id/fragment_master"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>
</LinearLayout>

This is my manifest file

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MasterActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
The4thIceman
  • 3,709
  • 2
  • 29
  • 36

4 Answers4

15

I added

android:windowSoftInputMode="adjustPan"

to my manifest within the activity tag, and now it works. I have never had to do that before, I guess my custom layout was messing with the keyboard somehow.

Thanks to @eee comment which pointed me in the right direction

The4thIceman
  • 3,709
  • 2
  • 29
  • 36
  • 1
    I've the similar issue, and this line didn't work for me – Canberk Ozcelik Mar 06 '17 at 16:47
  • @CanberkÖzçelik it has been a while since I have looked at this code and since then, 2 new versions of Android have come out. So something could have changed since then. – The4thIceman Mar 06 '17 at 19:09
  • 1
    Yup, but if anyone having the similar situation as not resolved, my question is here: http://stackoverflow.com/q/42597256/4432872 – Canberk Ozcelik Mar 07 '17 at 09:24
  • I had the same problem but with "AppBarLayout", after more than 5 hour looking for solution this answer saved me. if the one above didn't work try this `android:windowSoftInputMode="adjustNothing|adjustPan"` – Gazzx Sep 09 '19 at 00:15
  • what should you do if you want resize? – hmac Dec 09 '20 at 17:34
0

try to change ScrollView to androidx.core.widget.NestedScrollView

this helped me to fix the problem

Momen Zaqout
  • 1,508
  • 1
  • 16
  • 17
0

if you dont have set adjustPan set in your activity in AndroidManifest.xml f.e you need adjustResize then this was the only solution which helped me with that white blank space

EditText.setOnFocusChangeListener { v, hasFocus ->
    if (hasFocus) {
        // something if needed
    } else {
        Utils.hideKeyboardToAdjustPan(activity)
    }
}

fun hideKeyboardToAdjustPan(activity: Activity?) {
    activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
    hideKeyboard(activity)
}

fun hideKeyboard(activity: Activity?) {
    if (activity != null) {
        hideKeyboard(activity.currentFocus)
    }
}

fun hideKeyboard(view: View?) {
    if (view != null) {
        val inputManager = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        inputManager.hideSoftInputFromWindow(
            view.windowToken,
            WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED
        )
    }
}
Kebab Krabby
  • 1,574
  • 13
  • 21
0

In my case I have android:windowSoftInputMode="adjustResize" and it doesn't matter. In one layout when a list is too short and a keyboard shows, then hides, the list occupies smaller space. A blank space appears below the list (where the keyboard was shown).

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        ... >

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include
                layout="@layout/details"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" />

        </com.google.android.material.appbar.AppBarLayout>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="com.example.behavior.AutoSizeBehavior"> // Wrong class

            <androidx.recyclerview.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </FrameLayout>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

I tried to change app:layout_scrollFlags="scroll|exitUntilCollapsed|snap", but it was not good for scrolling. Then I replaced CoordinatorLayout with NestedScrollView, it helped, but the layout changed. After that I noticed that app:layout_behavior referred to a custom class (with bugs). I changed it to @string/appbar_scrolling_view_behavior. You can also change to com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.

CoolMind
  • 26,736
  • 15
  • 188
  • 224