Tom Darious
Tom Darious

Reputation: 533

Fragment is being shifted up when the keyboard is showing

In my Android app, whenever the user selects the TextView, the keyboard shows up but it shifts my fragment up. I have tried the following in my onViewCreated and it didn't work:

[email protected]().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

How do I prevent my keyboard from shifting up the fragment? I want the fragment to be fixed and when the TextView is selected, the keyboard is simply on top of the fragment.

Upvotes: 1

Views: 1449

Answers (1)

che10
che10

Reputation: 2318

I think you need to add adjustPan flag to your activity in AndroidManifest. There are two main flags which are the following.

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.

So I suggest you use the adjustPan which seems what you want

<activity android:windowSoftInputMode="adjustPan"> </activity>

Upvotes: 1

Related Questions