我正在使用 AndEngine 制作一个游戏,它使用设备的软键盘。
我没有使用EditText
,而是我自己的。我正在尝试检测软键盘上的按下情况,
我已经成功地在 AndEngine 场景中显示和隐藏键盘。
我的 Activity 实现了 OnKeyboardActionListener
,我读到它用作软键盘监听器,但我不确定如何使用 this
类注册键盘( Activity )。
显然,目前 onPress()
中的代码是没有用的..
我找不到任何示例,其中大多数都引用了 EditText
,我没有使用它。
是否可以?
也许是服务或其他什么?
提前致谢。
编辑:
我正在尝试使用 KeyboardView
和自定义 Keyboard
创建自己的键盘,
这样我就可以做到
KeyboardView kbView = new KeyboardView(this,null);
kbView.setKeyboard(new Keyboard(this, R.xml.keyboard);
kbView.setOnKeyboardActionListener(new OnKeyboardActionListener() {
....
}
有人做过吗?有效,不是吗?
谢谢。
最佳答案
我最终创建了自己的 Keyboard
和 Keyboard
View`,然后我使用了这段代码
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
}
....
}
并在xml布局中创建了一个KeyboardView
<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
,不知道为什么,但它适用于自定义而不适用于原始
编辑:
另外,该 Activity 扩展了 SimpleLayoutGameActivity
,然后我选择了包含 CustomKeyboardView
关于java - 软键盘监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13114726/