2013-10-25 183 views
0

因为它是一个promptView而不是一个Activity,我不能去Manifest来隐藏键盘。 我搜索了谷歌周围,我发现类似的主题,但我无法弄清楚如何把这个工作。Android AlertDialog(promptview)隐藏键盘

LayoutInflater li = LayoutInflater.from(this); 
View promptsView = li.inflate(R.layout.prompt_firstime, null); 

final EditText nameInput = (EditText) promptsView.findViewById(R.id.prompt_name); 
final EditText emailInput = (EditText) promptsView.findViewById(R.id.prompt_email); 

InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(nameInput.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); 
inputManager.hideSoftInputFromWindow(emailInput.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); 

AlertDialog alertDialog = new AlertDialog.Builder(Menu.this).create(); 
alertDialog.setTitle("Title"); 
alertDialog.setView(promptsView); 
// etc 

我在做什么错了?谢谢。

回答

0

试试这个,它可能会解决你的问题。

your_activityName.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
+0

NOP。它继续显示键盘:| – user2902515

0

试试这个方法,只是通过你的活动范围内,同时呼吁

public static void hidekeypad(Activity activity) 
    { 
     @SuppressWarnings("static-access") 
     InputMethodManager imm = (InputMethodManager) activity.getSystemService(activity.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); 
    } 
+0

我应该如何调用该功能? 'hidekeypad(this)',如果是这样,我得到错误。 '10-25 09:08:14.470:E/AndroidRuntime(2777):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.testing/com.example.testing.Menu_activity}:java.lang.NullPointerException' 我在@oncreate方法上调用了函数。 – user2902515

+0

邮政编码你是怎么试过的? –

0

请尝试以下..它的工作在我的情况:)

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       imm.hideSoftInputFromWindow(your_edit_text.getWindowToken(), 0); 
+0

Doens't工作。 – user2902515