0

What I am trying to do: The keyboard should show at bottom of the dialog.

Code: I am extending the Dialog class.

  window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)

What I have tried:

  1. window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)

  2. window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)

As I have studied here, SOFT_INPUT_ADJUST_RESIZE should work but I am not able to figure out why It is not working in my case?

login Screen

Ankur_009
  • 3,333
  • 4
  • 27
  • 46

1 Answers1

5

Add following property into your activity tag (AndroidManifest.xml)

android:windowSoftInputMode="adjustResize"

Also you need to add below code in OnCreate function (MainActivity.java)

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

This solved the problem and it worked perfectly fine on all resolution emulators and samsung devices. It did fail, though, on Google Nexus S device and I could see the same problem again of virtual keyboard hiding the EditTexts.

You can try below code to make dialog adjustable as per keyboard status.

alertDialog.getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Note -: If you are using Dialog instead of alert Dialog do the below changes.

Create one style file e.g. dialog.xml. Put below code into it.

<style name="DialogStyle" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowSoftInputMode">stateUnchanged</item>
    <item name="android:windowBackground">#22AAEA</item>
</style>

Now apply style to dialog.

final Dialog dialog = new Dialog(this , R.style.dialog);

NOTICE that the attribute "parent" is "Theme.Black.NoTitleBar.Fullscreen" like a activity's style. and the attribute "android:windowFullScreen" should be false.

Now, the dialog will be resized when the soft keyboard toggled.

Flutterian
  • 1,643
  • 1
  • 19
  • 43