2

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,823
  • 4
  • 31
  • 47
  • Post the full dialog class code..for better understanding – rafsanahmad007 Nov 27 '17 at 08:44
  • Right before your onCreate ending parenthesis, simply add this code: this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); and your Manifest to change as: android:windowSoftInputMode="adjustResize" in the among of the activity codes within. – Bay Dec 13 '22 at 20:12

2 Answers2

8

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,761
  • 1
  • 21
  • 47
0

Recently SOFT_INPUT_ADJUST_RESIZE is deprecated in Java, so is better change it. Here, there is a way:

Theme_Material_Dialog_Presentation 

in Style or AlertDialog.Builder such as:

val dialogBuilder = AlertDialog.Builder(this,
                        android.R.style.Theme_Material_Dialog_Presentation)
Mori
  • 2,653
  • 18
  • 24