簡體   English   中英

在Android對話框中沒有顯示鍵盤

[英]No show keyboard in dialog on Android

我有一個活動,單擊按鈕后會顯示一個對話框。 但是鍵盤未顯示在對話框中。 我的這段代碼:

final DialogComfigPass comfigPass = new DialogComfigPass(ActivityTable.this);
comfigPass. getWindow (). clearFlags ( WindowManager . LayoutParams . FLAG_NOT_FOCUSABLE | WindowManager . LayoutParams . FLAG_ALT_FOCUSABLE_IM );
comfigPass.show();`

**您必須在這樣的對話框中打開鍵盤**

    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {

            InputMethodManager inputMethodManager = (InputMethodManager)this.getSystemService(
                            Context.INPUT_METHOD_SERVICE);
            inputMethodManager.toggleSoftInput(
                    InputMethodManager.SHOW_FORCED, 0);
        }
    });

您可以使用setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);‌​

  // Show the keyboard when the dialog is displayed on the screen.
comfigPass.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);‌​

之前

comfigPass.show();

最后

final DialogComfigPass comfigPass = new DialogComfigPass(ActivityTable.this);
comfigPass. getWindow (). clearFlags ( WindowManager . LayoutParams . FLAG_NOT_FOCUSABLE | WindowManager . LayoutParams . FLAG_ALT_FOCUSABLE_IM );
comfigPass.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);‌​
comfigPass.show();`

嘗試它會起作用:) comfigPass.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);‌​

請用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM