2015-07-22 37 views
1

我想在創建活動時顯示鍵盤。但鍵盤沒有顯示。即使使用editText.requestFocus也不顯示鍵盤

我使用Nexus_5_API_22_x86模擬器

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_ex); 
    EditText editText = (EditText) findViewById(R.id.ex); 
    InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE); 
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
    editText.requestFocus(); 
} 

可能是什麼問題?

我也試過它沒有在啓動時顯示鍵盤:

@Override 
public void onResume() { 
    super.onResume(); // Always call the superclass method first 

    TimerTask tt = new TimerTask() { 

     @Override 
     public void run() { 
      EditText editText = (EditText) findViewById(R.id.ex); 
      editText.requestFocus(); 
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
     } 
    }; 

    final Timer timer = new Timer(); 
    timer.schedule(tt, 200); 

} 
+0

什麼是模擬器的配置?你有「鍵盤支持」活動嗎? – JDenais

回答

1

我沒有和例子來看看這和線爲我工作是這個打開

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 

並關閉

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

編輯

我試圖在三星Galaxy S4(真實設備)

在模擬器我的例子鍵盤不會顯示

0

你試過設置requestFocus()方法第一次像這樣

editText.requestFocus(); 
InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE); 
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
+0

是的...我嘗試過......沒有工作....我也試過onResume與一個計時器....沒有工作 – GJain