[英]How the soft keyboard long press backspace works?
我正在Android上創建一種輸入法,並且我想實現長按退格鍵來不刪除而逐個刪除字符(我認為默認行為是刪除一個字符后按退格鍵)。
我當前的解決方案是“覆蓋”我的“ KeyboardView”子類中的“ onLongPress”函數,並在觸發長按“ KEYCODE_DELETE”代碼的調用時,調用持續運行刪除以將刪除操作發送到視圖。 如以下代碼所示:
@Override
protected boolean onLongPress(Key key) {
if (key.codes[0] == Keyboard.KEYCODE_DELETE) {
final Handler h = new Handler();
final int delay = 500;
h.postDelayed(new Runnable() {
public void run() {
h.postDelayed(this, delay);
getOnKeyboardActionListener().onKey(Keyboard.KEYCODE_DELETE, null);
}
}, delay);
return true;
} else {
return super.onLongPress(key);
}
}
因此,我的問題是“如何阻止它?” 如何跟蹤長按退格鍵的釋放? 還是有什么辦法可以使長按刪除發生?
我正在學習中。
看來可行,但我不確定是否正確。
使用android:isRepeatable="true"
。
您不必使用onLongPress
。
onKey的工作原理相同。
XML文件
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0px" android:verticalGap="0px"
android:keyWidth="100%p" android:keyHeight="70dp">
<Row>
<Key android:codes="-5" android:keyIcon="@drawable/ic_action_name" android:isRepeatable="true">
</Row>
</Keyboard>
Java類
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
switch(primaryCode) {
case Keyboard.KEYCODE_DELETE:
ic.deleteSurroundingText(1, 0);
break;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.