Android keyboard 多键值的问题

https://developer.android.google.cn

onKey

added in  API level 3
 
public abstract void onKey (int primaryCode, int[] keyCodes)

Send a key press to the listener.

Parameters
primaryCodeint: this is the key that was pressed

keyCodesint: the codes for all the possible alternative keys with the primary code being the first. If the primary key code is a single character such as an alphabet or number or symbol, the alternatives will include other characters that may be on the same key or adjacent keys. These codes are useful to correct for accidental presses of a key adjacent to the intended key.

官方解释够权威了吧。在 softkeyboard 示例代码里,keyCodes 的使用出现 3 次。
    public void onKey(int primaryCode, int[] keyCodes) {
        if (isWordSeparator(primaryCode)) {
            // Handle separator
            if (mComposing.length() > 0) {
                commitTyped(getCurrentInputConnection());
            }
            sendKey(primaryCode);
            updateShiftKeyState(getCurrentInputEditorInfo());
        } else if (primaryCode == Keyboard.KEYCODE_DELETE) {
            handleBackspace();
        } else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
            handleShift();
        } else if (primaryCode == Keyboard.KEYCODE_CANCEL) {
            handleClose();
            return;
        } else if (primaryCode == LatinKeyboardView.KEYCODE_OPTIONS) {
            // Show a menu or somethin'
        } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE
                && mInputView != null) {
            Keyboard current = mInputView.getKeyboard();
            if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) {
                current = mQwertyKeyboard;
            } else {
                current = mSymbolsKeyboard;
            }
            mInputView.setKeyboard(current);
            if (current == mSymbolsKeyboard) {
                current.setShifted(false);
            }
        } else {
            handleCharacter(primaryCode, keyCodes);
        }
    }
    private void handleCharacter(int primaryCode, int[] keyCodes) {
        if (isInputViewShown()) {
            if (mInputView.isShifted()) {
                primaryCode = Character.toUpperCase(primaryCode);
            }
        }
        if (isAlphabet(primaryCode) && mPredictionOn) {
            mComposing.append((char) primaryCode);
            getCurrentInputConnection().setComposingText(mComposing, 1);
            updateShiftKeyState(getCurrentInputEditorInfo());
            updateCandidates();
        } else {
            getCurrentInputConnection().commitText(
                    String.valueOf((char) primaryCode), 1);
        }
    }

使用多键的例子:

<Key android:codes="46,44" android:keyLabel=". ,"
                android:keyWidth="15%p"/>

(1)在 softkeyboard 示例里,keyCodes 多键值是有效的;

(2)在 strocomp 代码里,初始化 android:codes = "0,0",获取 keyCodes[1] 为 -1。不知为何?

存疑。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
React Native的 `react-native-android-keyboard-adjust` 库可以用来调整安卓键盘的行为。在0.63版本中,使用方法如下: 1. 安装库 使用以下命令安装库: ``` npm install react-native-android-keyboard-adjust ``` 2. 链接原生代码 使用以下命令来链接原生代码: ``` npx react-native link react-native-android-keyboard-adjust ``` 或者手动链接,按照以下步骤: (1) 在 `android/settings.gradle` 文件中添加以下代码: ``` include ':react-native-android-keyboard-adjust' project(':react-native-android-keyboard-adjust').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-keyboard-adjust/android') ``` (2) 在 `android/app/build.gradle` 文件中添加以下代码: ``` dependencies { // ... implementation project(':react-native-android-keyboard-adjust') } ``` (3) 在 `MainApplication.java` 文件中导入以下代码: ``` import com.reactnativeandroidkeyboardadjust.ReactNativeAndroidKeyboardAdjustPackage; ``` (4) 在 `MainApplication.java` 文件的 `getPackages()` 方法中添加以下代码: ``` new ReactNativeAndroidKeyboardAdjustPackage() ``` 3. 使用 在需要调整键盘行为的组件上,添加 `androidKeyboardAdjust` 属性,值可以为以下三种: - `none`: 不调整键盘行为 - `pan`: 键盘出现时,组件会向上滚动,以避免被键盘遮挡 - `resize`: 键盘出现时,组件会自动调整大小,以避免被键盘遮挡 例如: ```jsx <TextInput androidKeyboardAdjust="pan" // ... /> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值