6
votes

My goal is to achieve what most messaging apps like Facebook messenger, Viber, What's up do when displaying an attachment sheet. If the Soft keyboard is visible and the user wants to attach something, the keyboard is hidden and the attachment sheet is presented in its place.

In order to make this work, the layout changes should happen when the root view size changes. Otherwise, a graphical glitch occurs where my layout changes are applied shortly before keyboard is shown/hidden.

If I could change my layout the exact moment the keyboard is hidden, I could get it right. I have tried using onGlobalLayoutListener but without the desired outcome.

enter image description here

3

3 Answers

0
votes

Add this line in the manifest of your activity.

 <activity
        android:name="com.your.Activity"
        android:windowSoftInputMode="stateHidden|adjustPan" />
0
votes

Use this code It will be Helpful.

android:windowSoftInputMode="adjustNothing"
0
votes

The best place to find out whether your layout changed due to the keyboard (dis)appearing and acting on the change is inside onMeasure() of the root layout.

In more detail, I made a custom LinearLayout, which is used as my root layout. I overrided the onMeasure and I calculate what is the current keyboard height. Depending on the keyboard's height and whether my attachment grid should be visible or not, I change the visibility of the attachment grid. I can even set the grid's height the same as the keyboard.

The results looks like the grid was always beneath the keyboard and the textview remains in the same vertical place.