9

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

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

目的地搜索.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(destinationSearch, InputMethodManager.SHOW_IMPLICIT);

有没有办法在横向模式下显示软键盘?

4

4 回答 4

12

您需要使用强制显示

InputMethodManager imm;
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.showSoftInput(this.editText,InputMethodManager.SHOW_FORCED);
于 2011-01-25T13:59:07.670 回答
3

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

我更喜欢添加

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

到我的 EditTextStyle 所以我总是可以赶上 onGlobalLayout() 等等。现在您可以使用 SHOW_IMPLICIT。只需确保您的 UI 在如此小的区域内看起来不错,如果不需要,请删除自动更正。

于 2015-02-19T23:18:25.113 回答
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);

    } 
}); 
于 2015-06-06T18:02:01.997 回答
0

更简单的 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

<请求焦点 />

于 2020-10-15T18:45:23.390 回答