1

My dialog is in the center of the screen which have 3 edit text and button. When I focus on my first edittext, I want the whole dialog to be on top of keyboard to show my button at the bottom of dialog.

I have tried almost alll answer here..

var dialog = builder.create()

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

return dialog

Note: This is just dialog, so no need to put something in manifest.?..

lets say i have this as dialog ----> i47.tinypic.com/2vchnih.png

I want my dialog to be on TOP of keyboard NOT something like this ----> i45.tinypic.com/352lym9.png

xigncode23
  • 101
  • 3
  • 9

2 Answers2

0

Try this code, You also need to set Width and Height manually

  WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        params.gravity = Gravity.CENTER;
        window.setAttributes(params); 
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
Abubakker Moallim
  • 1,610
  • 10
  • 20
  • I just tried that ----> https://stackoverflow.com/questions/12189776/how-can-i-display-a-dialog-above-the-keyboard It seems the dialog is limited on the screen to go up. – xigncode23 Dec 20 '17 at 06:11
  • can you attach and screenshot of what you want – Abubakker Moallim Dec 20 '17 at 06:12
  • lets say i have this as dialog ----> http://i47.tinypic.com/2vchnih.png I want my dialog to be on TOP of keyboard NOT something like this -----> http://i45.tinypic.com/352lym9.png – xigncode23 Dec 20 '17 at 06:19
  • With this code it should solve your problem . can u give a screenshot after this. See it will just keep your editText focusable . Not your buttons – Abubakker Moallim Dec 20 '17 at 06:22
  • btw, ADJUST PAN and ADJUST RESIZE cannot use at the same time...?! – xigncode23 Dec 20 '17 at 06:39
  • Read this for your clearance : https://stackoverflow.com/questions/17410499/difference-between-adjustresize-and-adjustpan-in-android – Abubakker Moallim Dec 20 '17 at 06:43
  • You whole dialog will not go up with any of this. Your editText will be visible that your focusing will be visible with Adjust_Resize – Abubakker Moallim Dec 20 '17 at 06:44
0

You need a fullscreen dialog for this .Set your dialog's theme as .

<style name="fullScreeDialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>

Xml layout .

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/blue_end"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingBottom="30dp">

    <EditText
        android:id="@+id/et1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:padding="20dp"
        android:text="hint" />
</LinearLayout>

Then build a dialog with match_parent window params.

private void buildDialog() {
        Dialog dialog=new Dialog(this,R.style.fullScreeDialog);
        dialog.setContentView(R.layout.item_dialog);
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        dialog.getWindow().setAttributes(params);
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
        dialog.show();
    }

Output is - Output

ADM
  • 20,406
  • 11
  • 52
  • 83
  • editttext is visible, but at the bottom of that edittext theres button. and I want the button to show after keyboard is called... – xigncode23 Dec 20 '17 at 07:19
  • I think Dialog position relative to Soft keyboard is depends upon the currently focused view . – ADM Dec 20 '17 at 07:45
  • yes like this ---> https://stackoverflow.com/questions/5622202/how-to-resize-alertdialog-on-the-keyboard-display but I want my whole dialog to show :(' – xigncode23 Dec 20 '17 at 07:54