2011-01-21 75 views
7

此代碼似乎並沒有在風景模式下工作:顯示軟鍵盤時,該設備是橫向模式

EditText destinationSearch = (EditText) findViewById(R.id.destinationSearch); 

destinationSearch.requestFocus(); InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(destinationSearch,InputMethodManager.SHOW_IMPLICIT);

是否有任何解決方案來顯示風景模式下的軟鍵盤?

+0

似乎與SHOW_FORCE標誌一起使用:D – andreea

回答

10

您需要使用展示被迫

InputMethodManager imm; 
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY); 
imm.showSoftInput(this.editText,InputMethodManager.SHOW_FORCED); 
+0

爲什麼需要toggleSoftInput與HIDE_IMPLICIT_ONLY? –

1

的原因是,風景模式最經常放軟鍵盤在一個新的全屏窗口。正如Bakih所說,武力會起作用,但全屏幕窗口有更多效果,SHOW_FORCED也是如此。

我更喜歡加入

<item name="android:imeOptions">flagNoFullscreen</item> 

我EditTextStyle所以我總是趕onGlobalLayout()等。現在你可以使用SHOW_IMPLICIT了。只要確保你的用戶界面在這樣一個小區域看起來不錯,如果不需要的話刪除自動更正。

0
EditText editText = (EditText)findViewById(R.id.editText); 

editText.setFocusableInTouchMode(false); 

final Context context = this; 

editText.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 

     v.requestFocusFromTouch(); 

     InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.showSoftInput(v, InputMethodManager.SHOW_FORCED); 

    } 
}); 
+2

您可能會發現向答案添加解釋很有用,因此讀者可以瞭解爲什麼您的答案是最好的,而不僅僅是郵政編碼。您可以通過按下「編輯」按鈕來添加答案。 –

相關問題