Jin
Jin

Reputation: 472

Android soft keyboard showing under a dialog fragment

I have a dialog fragment, which has a listview with mutiple views listed, in one of that view there is an edittext which has showing cursor, but soft keyboard is not showing. So i write a code on its onclick to show keyboard like below,

etcomment.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                }
            });

Now keyboard is showing, but it is showing under that DialogFragment

enter image description here

I searched but didn't get an answer, please help me!

Upvotes: 2

Views: 1620

Answers (1)

DJphy
DJphy

Reputation: 1302

Your window params is the problem Okay u should do like this:..

    Dialog dialog = new Dialog(DialogTestKeyboard.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width  = 400;
    lp.height = 800;
    dialog.setContentView(yourLayoutHavingEditText);
    dialog.setCancelable(false);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.show();
    dialog.getWindow().setAttributes(lp);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Upvotes: 4

Related Questions