如何在 Android 上调整键盘焦点布局?

How to adjust keyboard foucus layout on Android?

这是我单击编辑文本时的键盘放大视图。

问题是:

  1. 太大了,只有一小段编辑文本就足够了。
  2. 键盘有时浮动有时停靠不知道是什么控制它。
  3. 不需要那个完成按钮和绿线
  4. 输入完成后的回调函数是什么

这是请求软键盘弹出的方法

    public void editText(){
       Toast.makeText(mContext, "Editing Text",Toast.LENGTH_SHORT).show();
       InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
       mEditText.setVisibility(VISIBLE);
       mEditText.requestFocus();
       mEditText.setText(mText);
       imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
    }

编辑文本的属性

<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:hint="annotation text"
    android:inputType="text"
    android:textSize="14sp"
    android:visibility="gone"/>

当您将设备方向更改为横向时,这是默认布局。

添加

android:imeOptions="flagNoExtractUi|flagNoFullscreen"

禁用全屏编辑视图

<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:imeOptions="flagNoExtractUi|flagNoFullscreen"
    android:hint="annotation text"
    android:inputType="text"
    android:textSize="14sp"/>

flagNoExtractUi Used to specify that the IME does not need to show its extracted text UI. For input methods that may be fullscreen, often when in landscape mode, this allows them to be smaller and let part of the application be shown behind. Though there will likely be limited access to the application available from the user, it can make the experience of a (mostly) fullscreen IME less jarring. Note that when this flag is specified the IME may not be set up to be able to display text, so it should only be used in situations where this is not needed.

flagNoFullscreen Used to request that the IME never go into fullscreen mode. Applications need to be aware that the flag is not a guarantee, and not all IMEs will respect it.