繁体   English   中英

当设备处于横向模式时显示软键盘

[英]Show soft keyboard when the device is landscape mode

此代码似乎不适用于横向模式:

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

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

是否有任何解决方案可以在横向模式下显示软键盘?

您需要使用强制显示

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

原因是横向模式最常将软键盘放在新的全屏窗口中。 正如 Bakih 所说,力会起作用,但全屏窗口有更多效果,SHOW_FORCED 也是如此。

我更喜欢添加

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

到我的 EditTextStyle 这样我就可以随时捕捉 onGlobalLayout() 等等。 现在您可以使用 SHOW_IMPLICIT。 只需确保您的 UI 在如此小的区域内看起来不错,并在不需要时删除自动更正。

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);

    } 
}); 

更简单的 XML 更改答案https://stackoverflow.com/a/13179855/1029110

 <EditText   
        android:id="@+id/txtInLandscapeVw"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="flagNoExtractUi">   
        <requestFocus />
    </EditText>

所以添加

android:imeOptions="flagNoExtractUi

<请求焦点/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM