C# 检测Android自定义键盘中的isSticky

C# 检测Android自定义键盘中的isSticky,c#,android,xml,xamarin,C#,Android,Xml,Xamarin,我有一个自定义键盘,上面的按钮已启用isSticky,但我无法检测它是否打开或关闭(真/假),并且在按下任何键(如果打开)(真)后也无法禁用它们 问题是我找不到一种方法来检测按键,也无法将当前的edittext附加到函数中(所有的粘性按钮都有特定的函数) 这应该发生在OnKey函数中 这是我的键盘课: public class MyKeyboardListener : Java.Lang.Object, KeyboardView.IOnKeyboardActionListener{ p

我有一个自定义键盘,上面的按钮已启用isSticky,但我无法检测它是否打开或关闭(真/假),并且在按下任何键(如果打开)(真)后也无法禁用它们

问题是我找不到一种方法来检测按键,也无法将当前的edittext附加到函数中(所有的粘性按钮都有特定的函数)

这应该发生在OnKey函数中

这是我的键盘课:

public class MyKeyboardListener : Java.Lang.Object, KeyboardView.IOnKeyboardActionListener{

    private readonly Activity _activity;

    public MyKeyboardListener(Activity activity){
        _activity = activity;
    }

    public void OnKey(Android.Views.Keycode primaryCode, Android.Views.Keycode[] keyCodes){
        var eventTime = DateTime.Now.Ticks;
        var keyEvent = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, primaryCode, 0);

        switch ((int)primaryCode) {
            case 1005:
            break;

            case 1006:
            break;

            default:
                _activity.DispatchKeyEvent(keyEvent);
            break;
        }
    }

    public void OnPress(Android.Views.Keycode primaryCode){
    }

    public void OnRelease(Android.Views.Keycode primaryCode){
    }

    public void OnText(Java.Lang.ICharSequence text){
    }

    public void SwipeDown(){
    }

    public void SwipeLeft(){
    }

    public void SwipeRight(){
    }

    public void SwipeUp(){
    }
}
Keyboard.axml

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="100%"
android:keyHeight="6%p">
<Row>
    <Key
        android:codes="1000"
        android:keyLabel="A"
        android:keyEdgeFlags="left"
        android:isModifier="true" 
        android:isSticky="true"
        android:horizontalGap="1%p" />
    <Key
        android:codes="1001"
        android:keyLabel="B"
        android:isModifier="true" 
        android:isSticky="true"
        android:horizontalGap="1%p" />
    <Key
        android:codes="1002"
        android:keyLabel="C"
        android:isModifier="true" 
        android:isSticky="true"
        android:horizontalGap="1%p" />
    <Key
        android:codes="1003"
        android:keyLabel="D"
        android:isModifier="true" 
        android:isSticky="true"
        android:horizontalGap="1%p" />
    <Key
        android:codes="1004"
        android:keyLabel="E"
        android:keyEdgeFlags="right"
        android:isModifier="true" 
        android:isSticky="true"
        android:horizontalGap="1%p" />
</Row>
<Row>
    <Key
        android:codes="8"
        android:keyLabel="1"
        android:keyEdgeFlags="left"
        android:horizontalGap="1%p" />
    <Key
        android:codes="9"
        android:keyLabel="2"
        android:horizontalGap="1%p" />
    <Key
        android:codes="1005"
        android:keyLabel="F"
        android:horizontalGap="1%p" />
    <Key
        android:codes="1006"
        android:keyLabel="G46"
        android:horizontalGap="1%p" />
    <Key
        android:codes="67"
        android:keyLabel="DELETE"
        android:keyEdgeFlags="right"
        android:horizontalGap="1%p" />
</Row>
</Keyboard>

在公共类内部
拉丁键盘视图
扩展
键盘视图
,重写
onDraw
方法,并使用以下代码获取粘滞键和修改键

List<Key> keys = getKeyboard().getKeys();
for (Key key : keys) {
    Drawable npd;
    // int drawable = R.drawable.btn_normal_with_shadow_t1;
    int drawable = R.drawable.key_normal;
    textColor = sessionManager.getSimpleyKeyTextColor();

    if (key.pressed) {
        drawable = R.drawable.key_normal;
    } else {
        if (key.modifier && key.sticky) {
            drawable = R.drawable.stickey_with_shad_bord;
            textColor = sessionManager.getSimpleyKeyTextColorModifiers();
        } else if (key.modifier) {
            drawable = R.drawable.modifier_btn_with_bord_shad;
            textColor = sessionManager.getSimpleyKeyTextColorModifiers();
        } else {
            drawable = R.drawable.key_normal;
        }
    }
<Key
    android:codes="-1"
    android:isModifier="true"
    android:keyWidth="14.8%p"
    android:keyEdgeFlags="left"
    android:keyIcon="@drawable/ic_shift_normal" />