2013-03-27 41 views
1

我對SO研究很多答案,並拿出了下面的代碼顯示鍵盤時,我則會彈出一個對話框:顯示鍵盤時AlertDialog彈出

final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
    alertDialog.setTitle("Title"); 
    final EditText input = new EditText(this); 
    input.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View view, boolean focused) { 
      alertDialog 
        .getWindow() 
        .setSoftInputMode(
          WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 

     } 
    }); 
    input.setFocusable(true); 
    input.requestFocus(); 
    alertDialog.setView(input); 

      alertDialog.show(); 

的對話框顯示,但鍵盤沒有按」不會彈出。如果這有所作爲,這全都在onTouch(...)方法中。

我的應用程序僅適用於橫向模式。我發現在肖像模式下,它正在顯示。爲什麼是這樣?

任何幫助表示讚賞。

回答

0

它看起來像是橫向模式,把我扔了。下面的代碼塊立即解決這個問題:

imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 
         InputMethodManager.HIDE_IMPLICIT_ONLY); 
       imm.showSoftInput(input, InputMethodManager.SHOW_FORCED); 
       alertDialog 
         .getWindow() 
         .setSoftInputMode(
           WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
+0

'setSoftInputMode'是enough.I試着和它的作品http://stackoverflow.com/a/30598731/730807 – 2015-06-02 15:12:18