Abd*_*jid 5 java android android-input-method custom-keyboard android-custom-keyboard
我想在键盘(Android IME)中创建一个像 Gboard 这样的搜索栏,如图所示。
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>
Run Code Online (Sandbox Code Playgroud)
但问题是当我按下edittext 2(在我的ime之外)然后我的ime打开,其中包含edittext 1,如上图所示,现在当我从我的ime中写一些东西时,它写在edittext 2而不是edittext 1上,所以我想知道这背后的问题是什么?有重点吗?或者是其他东西?
所以,我从上面Abdul Wajid的评论中得到了解决这个问题的线索。
我用这个LatinIME。只需要更新这一行
public void onEvent(final Event event) {
final InputTransaction completeInputTransaction =
mInputLogic.onCodeInput(mSettings.getCurrent(), event);
updateStateAfterInputTransaction(completeInputTransaction);
mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
}
Run Code Online (Sandbox Code Playgroud)
停止提交按下某些逻辑情况的事件键,
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());
}
}
Run Code Online (Sandbox Code Playgroud)
完成后,您可以控制按下的事件类型。
归档时间: |
|
查看次数: |
373 次 |
最近记录: |