0

I have made an app that has few EditTexts in the layout.

Once the EditText is Focused, the keyboard opens.

My layout is androidx.constraintlayout.widget.ConstraintLayout and I set each widget height to be some percent of the screen (like app:layout_constraintHeight_percent="0.2").

However, when the keyboard opens, it shrinks the widgets since now 0.2 percent of the screen is smaller compared to how it was before.

Is there a way to keep the weight percent to be with regard to the initial size only?

Thank you

Ben
  • 1,737
  • 2
  • 30
  • 61

1 Answers1

0

What you need is to specify the behaviour of the keyboard when visible through the android:windowSoftInputMode tag.

  • 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.
  • adjustResize: The activity's main window is always resized to make room for the soft keyboard on screen.

full documentation can be found here

In the Manifest.xml file please add this to your activity :

<activity
        android:windowSoftInputMode="stateVisible|adjustPan" ... >
        ...
</activity>

Happy coding!

AouledIssa
  • 2,528
  • 2
  • 22
  • 39
  • I used AdjustResize but it shrinks the screen. AdjustPan just dont do nothing since the EditTexts are above the keyboard is it shouldnt move anything. Still I want it to move because I have a button under the keyboard. – Ben Apr 14 '20 at 13:00
  • I hope this solves your problem https://stackoverflow.com/a/27854129/2057782 – AouledIssa Apr 14 '20 at 13:09