0

我正在使用使用设备软键盘的 AndEngine 制作游戏。

我没有使用EditText,而是我自己的。我正在尝试检测软键盘上的按下,我已经成功地在 AndEngine 场景中显示和隐藏键盘。

我的活动实现了OnKeyboardActionListener,我阅读它用作软键盘侦听器,但我不确定如何使用this类(活动)注册键盘。显然,此刻,里面的代码onPress()是没用的..

我找不到任何示例,其中大多数是指EditText我没有使用的 .. 可能吗?也许是服务之类的?

提前致谢。

编辑:

KeyboardView我正在尝试使用和自定义创建自己的键盘Keyboard,这样我可以做到

KeyboardView kbView = new KeyboardView(this,null);
kbView.setKeyboard(new Keyboard(this, R.xml.keyboard);
kbView.setOnKeyboardActionListener(new OnKeyboardActionListener() {
    ....
}

有人做过吗?有效,不是吗?

谢谢。

4

1 回答 1

1

我最终创建了自己的KeyboardView` Keyboard,然后我使用了这段代码

CustomKeyboardView kbView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
kbView.setKeyboard(new Keyboard(this, R.xml.myCustomKeyboard);
kbView.setOnKeyboardActionListener(new OnKeyboardActionListener() {
    @Override
    public void onPress(int primaryCode) {
        // A Key was pressed
    }
    ....
}

KeyboardView在 xml 布局中创建了一个

<pathToCustomKeyboardView.CustomKeyboardView
    android:id="@+id/keyboard_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone"
    android:layout_alignParentBottom="true" />

CustomKeyboardView仅扩展KeyboardView,不知道为什么,但它适用于自定义而不是原始

编辑:另外,活动扩展SimpleLayoutGameActivity,然后我选择了包含CustomKeyboardView

于 2012-11-03T17:51:21.800 回答