Android: How to avoid layout being pushed when keyboard invoked

23,262

Solution 1

Read article here: http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
You should add in manifest android:windowSoftInputMode="adjustResize" parameter to your activity tag.

EDITED: Proper flag is: android:windowSoftInputMode="adjustResize"

Solution 2

Out of all properties under android:windowSoftInputMode in manifest the only thing that worked is

android:windowSoftInputMode="adjustNothing"

Solution 3

In my AndroidManifest file, I added the the following code to the activity:

android:windowSoftInputMode="adjustPan"

HISTORY

Actually, I tried AdjustResize and AdjustNothing but it didn't work on my end so I tried other ways. I found this answer useful and hope it solves your problem as well! :)

Share:
23,262
Jay Mayu
Author by

Jay Mayu

I'm iOS / React Native Developer but I also do some Android, HTML5, Laravel and NodeJS. You can follow me at Twitter @mayooresan or connect with me at LinkedIn If you like my answers and posts then probably you will like my blog Mayu's IT Diary

Updated on July 09, 2022

Comments

  • Jay Mayu
    Jay Mayu almost 2 years

    I have a layout as below

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="1">
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content">
        <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="Button" android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="Button" android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="Button" android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </LinearLayout>
    <ImageButton android:id="@+id/imageButton1" android:src="@android:drawable/stat_notify_sync_noanim" android:layout_height="fill_parent" android:layout_weight="1" android:layout_width="fill_parent"></ImageButton>
    <EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="match_parent">
        <requestFocus></requestFocus>
    </EditText>
    </LinearLayout>
    

    when the softkeyboard invoked by clicking on the edit text the whole layou is being pushed. Can i keep the buttons on the header fixed and let the imageview being pushed?? Because buttons are gonna act like navigation bar so it should be there even when the layout is being pushed up.

    Before enter image description here

    After enter image description here

  • Jay Mayu
    Jay Mayu over 12 years
    android:windowSoftInputMode="adjustPan" doesn't help :(
  • kibibyte
    kibibyte over 12 years
    Try android:windowSoftInputMode="adjustNothing". This link should be helpful.
  • ania
    ania over 12 years
    Please try: android:windowSoftInputMode="adjustResize", I've mistaken tags. This should work :)
  • Artem Russakovskii
    Artem Russakovskii over 12 years
    android:windowSoftInputMode="adjustNothing" is not a valid value exposed by the API - the project errors out with that.
  • oldergod
    oldergod over 11 years
    Would be nice to edit your real answer so we don't have to look into the comments to get the right one.
  • DeeV
    DeeV almost 11 years
    @ArtemRussakovskii Is this still the case? My app doesn't seem to error with it and it's working as needed. Only tested on HTC One with 4.1.
  • DeeV
    DeeV almost 11 years
    In fact it was suggested by my IDE which is how I found it.
  • Androbean Studio
    Androbean Studio over 7 years
    Cant believe, Its undocumented; but this solved my issue ! Thanks a lot.
  • Tiffany
    Tiffany about 7 years
    This solved my issue as well! Thank you, my layout was not a scrollable view so naturally it would push it upwards with the soft keyboard upon a fragment replace.
  • DoruChidean
    DoruChidean almost 7 years
    does anyone know if there are problems on older android versions, regarding 'adjustNothing' value ?