2013-03-18 39 views
4

有沒有辦法在對話框顯示時防止鍵盤自動出現。android會阻止在dialog.show上顯示鍵盤

這裏是我的代碼爲我的對話框

final Dialog dialog = new Dialog(this); 
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        dialog.setContentView(R.layout.shopping_cart_confirm_dialog); 
        TextView txtConfirmEmail = (TextView)dialog.findViewById(R.id.txtConfirmEmail); 
        ... 
        dialog.show(); 

非常感謝。

回答

9

試試這個

dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 
+0

感謝很多:) – 2013-03-19 00:24:03

+0

@讓 - 弗朗索瓦·歡迎您返回windowtoken。請投票。謝謝 – 2013-03-19 00:38:26

0

使用InputMethodManager你應該能夠隱藏鍵盤。

檢查hideSoftInputFromWindow。它接受由

View.getWindowToken() 


InputMethodManager mgr=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); 
mgr.hideSoftInputFromWindow(dialog.getWindow().getWindowToken(), 0);