【问题标题】:Gboard like search bar in Android IMEAndroid IME 中类似 Gboard 的搜索栏
【发布时间】:2019-08-06 03:40:19
【问题描述】:

我想创建一个类似 Gboard inside keyboard (Android IME) 的搜索栏,如图所示。

Gboard 示例:

我已经在 Keyboardview.xml 上实现了一个编辑文本,如图所示。

我的实现:

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>

但问题是当我按下edittext 2(即在我的ime之外)时,我的ime打开,其中包含edittext 1,如上图所示,现在当我从我的ime中写一些东西时,它写在edittext 2上而不是edittext 1 所以我想知道这背后的问题是什么?是重点吗?还是别的什么?

【问题讨论】:

  • abdul 你找到解决办法了吗?
  • 如果您找到任何解决方案,请分享?
  • 是的,您可以在此搜索面板打开时停止提交键入的字符,反之亦然。
  • @AbdulWajid 你能制作解决方案的sn-p代码吗?

标签: java android custom-keyboard android-input-method android-custom-keyboard


【解决方案1】:

所以,我从上面的Abdul Wajidcomment 中得到了解决这个问题的线索。

我用这个LatinIME。只需要更新这一行

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

停止提交在某些逻辑情况下按下的事件键,

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

完成后,您可以控制按下的事件类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    相关资源
    最近更新 更多