有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

此代码在横向模式下似乎不起作用:

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

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

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


共 (4) 个答案

  1. # 1 楼答案

    原因是横向模式通常将软键盘置于新的全屏窗口中。正如Bakih所说,强制将起作用,但全屏窗口会产生更多的效果,因此显示强制

    我更喜欢加上

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

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

  2. # 2 楼答案

    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);
    
        } 
    }); 
    
  3. # 3 楼答案

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

    <;requestFocus/>

  4. # 4 楼答案

    你需要使用show-forced

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