6

I want to create a search bar like Gboard inside keyboard (Android IME) as shown in picture.

Gboard Sample :

Gboard Sample

I have implemented an edittext on Keyboardview.xml as shown in picture.

My Implementation :

My Implementation

main_keyboard_frame.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:background="#cf060610"
    android:id="@+id/search_panel"
    android:visibility="invisible">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:hint="sdsddsd"
        android:id="@+id/ed"/>



</RelativeLayout>

But the problem is when i press the edittext 2 (that is outside my ime) then my ime is open that contains edittext 1 as shown in above picture now when i write some thing from my ime it writes on edittext 2 instead of edittext 1 so i want to know whats the problem behind this? is it with focus? or something else?

JJIqbal
  • 630
  • 1
  • 8
  • 23

1 Answers1

1

So, I got a clue to solve this, from Abdul Wajid's comment above.

I use this LatinIME. Just need to update this line

public void onEvent(final Event event) {
        final InputTransaction completeInputTransaction =
                mInputLogic.onCodeInput(mSettings.getCurrent(), event);
        updateStateAfterInputTransaction(completeInputTransaction);
        mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}

stop commit the event key pressed with some logical case,

public void onEvent(final Event event) {
    if (mEditField.isFocused()){
        Log.d("LatinIME : field focused", "On Event: " + event.getTextToCommit() );
        mEditField.append(event.getTextToCommit());
    } else {
        final InputTransaction completeInputTransaction =
                mInputLogic.onCodeInput(mSettings.getCurrent(), event);
        updateStateAfterInputTransaction(completeInputTransaction);
        mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
    }
}

and done, you can control the event type that pressed.

cigien
  • 57,834
  • 11
  • 73
  • 112
Zainal Fahrudin
  • 536
  • 4
  • 23