Java 当设备处于横向模式时显示软键盘
此代码在横向模式下似乎不起作用: destinationSearch.requestFocus();InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT\u方法\u服务)Java 当设备处于横向模式时显示软键盘,java,android,landscape,android-softkeyboard,Java,Android,Landscape,Android Softkeyboard,此代码在横向模式下似乎不起作用: destinationSearch.requestFocus();InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT\u方法\u服务) imm.showSoftInput(destinationSearch,InputMethodManager.SHOW\u隐式) 是否有任何解决方案可以在横向模式下显示软键盘?您需要使用show forced InputMethodM
imm.showSoftInput(destinationSearch,InputMethodManager.SHOW\u隐式)
是否有任何解决方案可以在横向模式下显示软键盘?您需要使用show forced
InputMethodManager imm;
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.showSoftInput(this.editText,InputMethodManager.SHOW_FORCED);
原因是横向模式通常将软键盘置于新的全屏窗口中。正如Bakih所说,强制将起作用,但全屏窗口会产生更多的效果,因此显示强制 我更喜欢加上
<item name="android:imeOptions">flagNoFullscreen</item>
flagNoFullscreen
到我的EditTextStyle,这样我就可以随时捕获OnGlobalYout()等等。现在您可以使用SHOW_IMPLICIT。只要确保您的UI在如此小的区域内看起来良好,如果不需要,请删除自动更正。更简单的XML更改
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);
}
});
所以加上
android:imeOptions=“flagNoExtractUi
及
似乎与SHOW\u FORCE标志配合使用:dw您为什么需要将softinput切换为HIDE\u IMPLICIT\u ONLY?您可能会发现为您的答案添加一个解释很有用,这样读者就可以看到为什么您的答案是最好的,而不仅仅是发布代码。您可以通过按“
编辑
”按钮添加到您的答案中。
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);
}
});
<EditText
android:id="@+id/txtInLandscapeVw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="flagNoExtractUi">
<requestFocus />
</EditText>