显示软键盘时,该设备是横向模式

问题描述:

此代码似乎并没有在风景模式下工作:显示软键盘时,该设备是横向模式

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

您需要使用展示*

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

为什么需要toggleSoftInput与HIDE_IMPLICIT_ONLY? –

的原因是,风景模式最经常放软键盘在一个新的全屏窗口。正如Bakih所说,武力会起作用,但全屏幕窗口有更多效果,SHOW_FORCED也是如此。

我更喜欢加入

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

我EditTextStyle所以我总是赶onGlobalLayout()等。现在你可以使用SHOW_IMPLICIT了。只要确保你的用户界面在这样一个小区域看起来不错,如果不需要的话删除自动更正。

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

您可能会发现向答案添加解释很有用,因此读者可以了解为什么您的答案是最好的,而不仅仅是邮政编码。您可以通过按下“编辑”按钮来添加答案。 –