2012-12-06 80 views
1

我有一个activity,它打开一个dialog,其中包含点击。只要dialog打开softkeyboard显示。我想阻止这一点。只有在dialog中单击edittext时,才会出现softkeyboard。我使用的是Android 4.在Android 4.0中隐藏对话框中的软键盘加载

在此先感谢

+0

尝试[这](http://stackoverflow.com/a/11732587/1436931)你''清单文件 –

+0

感谢在重播...对不起,它在对话框的情况下不工作 – Lincy

回答

0

这应该是任何情况下:

public void hideKeyboard() { 

      mActivity.runOnUiThread(new Runnable() { 
       public void run() { 
        InputMethodManager inputManager = (InputMethodManager) mActivity 
          .getSystemService(Context.INPUT_METHOD_SERVICE); 
        inputManager.hideSoftInputFromWindow(mActivity 
          .getCurrentFocus().getWindowToken(), 
          InputMethodManager.HIDE_NOT_ALWAYS); 
       } 
      }); 
     } 
+0

由于getCurrentFocus()返回null 。 Bungle先生的回答比较好。 – wize

+0

你需要传递你的活动实例,而不是毫无意义。但那么适合你更好。 :) – Lincy

3

要做到这一点,设置软输入模式下,你叫dialog.Show之前():

// Build and create your dialog. 
AlertDialog dialog = new AlertDialogBuilder(...).create(); 

// Hide soft keypad by default (will be displayed when user touches any edit field). 
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

// Show the dialog. 
dialog.show(); 
-1

加入给你的清单是所有你甲肝做:

机器人:windowSoftInputMode = “stateHidden”

简单,但如果有人在看着这里

:)

+0

用户询问隐藏在对话框中的键盘,而不是在活动 – wize

+0

检查已添加的答案wize – Lincy