Search code examples
javaandroidandroid-edittextandroid-softkeyboard

How to adjust keyboard foucus layout on Android?


This is my keyboard zoomin view when i click the edit text. enter image description here

Problem is:

  1. It is way too big only one small strip of edit text is enough.
  2. Keyboard sometimes floating sometimes docking dont know what controls it.
  3. No need of that finish button and green line
  4. What is the callback function once the input in done

This is the method request soft keyboard popup

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

Properties of edit text

<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"/>

Solution

  • It a default layout when you change your device orientation to landscape.

    Add

    android:imeOptions="flagNoExtractUi|flagNoFullscreen"
    

    to disable the fullscreen editing view

    <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.