2013-10-07 26 views
1

我正在使用隱藏的EditText(可見性未設置爲不可見,而是EditText具有0dp的寬度和高度)以接收用戶輸入。我正在使用輸入數據來填充其他TextView。我這樣做的原因是因爲我不希望可見窗體(TextViews)具有與實際EditText相同的屬性,但我確實想使用軟鍵盤。如何在單擊另一個TextView時將焦點添加到EditText

我的問題是,當用戶選擇隱藏鍵盤,無論是通過按回或「完成」按鈕,我想使它重新出現時,他們點擊一個TextView,讓他們再次可以開始編輯隱藏EditText。

我嘗試下面的代碼,但沒有成功:

if(hiddenEt.requestFocus()) { 
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
} 

if語句內的代碼並運行,但軟鍵盤不會重新出現。

是否有一個單獨的函數實際調用軟鍵盤?

回答

1

試試下面的代碼中的TextView對點擊..

hiddenEt.requestFocus(); 
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.showSoftInput(hiddenEt, InputMethodManager.SHOW_IMPLICIT); 
+0

工作就像一個魅力,謝謝! – Joey

+0

我會在55秒;) – Joey

+0

k..no probz::)) – Hariharan

0
InputMethodManager imm=(InputMethodManager)getSystemService(yourActivity.this.INPUT_METHOD_SERVICE); 
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 

清單檔案中的添加android:windowSoftInputMode="stateVisible|adjustResize|adjustPan"

<activity 
      android:name=".yourActivity" 
      android:configChanges="keyboardHidden|orientation" 
      android:screenOrientation="portrait" 
      android:windowSoftInputMode="stateVisible|adjustResize|adjustPan" > 
     </activity> 
相關問題