Change Android Keyboard behaviors for the whole app

Hello,
today i want to show you how you can change Keyboard behaviors for your whole App.
In Example how you prevent your Android Keyboard from pushing up your Content or buttons over your Keyboard and so on.

It is really simple!
Just go to your Project and if you havent already add android platform to your project with:
ionic platform add android
after that to be on the safe side do the following
ionic build android

So now go into your Project and go to:
platforms -> android -> AndroidManifest.xml

In that file search for:
android:windowSoftInputMode="adjustResize"
and change it to:
android:windowSoftInputMode="adjustPan"

With this Setting your Keyboard overlaps all and does not Scroll up or down or move Divs or Inputs and so on.

Here are some other settings:

adjustNothing
Ignores the whole Layout. If it gets opened it must be closed by the user.
stateUnspecified
The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme. This is the default setting for the behavior of the soft keyboard.
stateUnchanged
The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore.
stateHidden
The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
stateAlwaysHidden The soft keyboard is always hidden when the activity’s main window has input focus.
stateVisible
The soft keyboard is visible when that’s normally appropriate (when the user is navigating forward to the activity’s main window).
stateAlwaysVisible
The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
adjustUnspecified
It is unspecified whether the activity’s main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window’s contents visible within a smaller area. This is the default setting for the behavior of the main window.
adjustResize
The activity’s main window is always resized to make room for the soft keyboard on screen.
adjustPan
The activity’s main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

All this information can be found here:
Desenvolvedores Android  |  Android Developers

Cheers :slight_smile:

7 Likes

Thanks a ton. I was searching for this in every nook and cranny from last 2 days.This works :slight_smile:

1 Like

@Impromptu_Coder no problem im glad it works :slight_smile:

But if I want to do this junt in one page?

2 Likes

Same question as @AndreVicente

I want to use adjustResize for the vast majority of inputs, but for a few specific inputs, I want to use adjustPan.

Is this possible?

2 Likes

This is amazing! It solves a problem I’ve been struggling with for a while.

But does anyone knows how can I apply this change on the AndroidManifest through the config.xml file? My platforms folder (where the AndroidManifest is) is not under version control and sometimes we remove it and reinstall it so any change i make would be lost…

1 Like

Thanks a lot for this beautiful content.
The problem is while i put the

<preference name="android-windowSoftInputMode" value="adjustPan" />

in config.xml, it never builds in AndroidManifest.xml. Could you please help in that.
And, if i use adjustPan or adjustNothing, then things don’t get scroll when keyboard pops up.
Cheers.:+1:

Same problem, I can’t set it from config.xml, I tried THIS DOES NOT WORK

    <preference name="WindowSoftInputMode" value="adjustNothing" />
    <preference name="windowSoftInputMode" value="adjustNothing" />
    <preference name="android:windowSoftInputMode" value="adjustNothing" />
    <preference name="android-windowSoftInputMode" value="adjustNothing" />

For those who want to set android manifest properties through the config.xml, take a look at https://www.npmjs.com/package/cordova-plugin-settings-hook. I use this plugin to modify the android:windowSoftInputMode. Hope it helps :grinning:

1 Like

Under platform android

<preference name="android-manifest/application/activity/@android:windowSoftInputMode" value="adjustPan" />

in config.xml under platform Android:

<platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">         
            <activity android:windowSoftInputMode="adjustPan" />
        </edit-config>

work for me. Ionic 5

doesnt work for me in ionic 4 app … the strange thing is , in the first builds worked , and now that i have made the app complete it doesnt work anymore , i never changed the android.xml or anything of that sort … probably ionic can only scale ion items and not divs or some minor shortcoming like that …

1 Like

here never worked i dont know why