问题描述
我正在尝试使TextField处于焦点状态(可见键盘)时单击后退"按钮.
I'm trying to catch the Back button while the TextField is focused (keyboard is visible).
我已经尝试过使用Multiplexer
-在阶段的顶部设置'BackProcessor
'-不起作用:
I have already tried with Multiplexer
- setting the 'BackProcessor
' on the top of the stages - it doesn't work:
InputProcessor backProcessor = new InputAdapter() {
@Override
public boolean keyDown(int keycode) {
if ((keycode == Input.Keys.BACK) )
{
Gdx.app.log("INPUT", "BACK");
}
return false;
}
};
InputMultiplexer multiplexer = new InputMultiplexer(backProcessor,
loginStage,registerStage);
Gdx.input.setInputProcessor(multiplexer);
此外,我在render
方法中尝试使用:
Also, I tried in the render
method with:
if(Gdx.input.isKeyDown(Keys.BACK)
也不起作用.
上述解决方案在键盘可见的那一刻除之外都能完美地工作.
Above solutions work perfectly EXCEPT the moment, when the keyboard is visible.
我要实现的目标?当onScreenKeyboard可见时,我需要单击后退"按钮.
What I'm trying to achieve?I need to catch the Back Button when the onScreenKeyboard is visible.
我也尝试过使用TextFieldListener
,但是"BackButton"是一个没有任何字符代码"的键,因此无法在其中被捕获:
I also tried with TextFieldListener
but 'BackButton' is the one key that hasn't any 'char code' so it can't be catched there:
public void keyTyped(TextField textField, char c)
最终编辑
正如LibGDX的作者所说-无法以正常方式检索此消息,因为在可见键盘时按下后退按钮是在应用程序外部进行处理的. Android解决方案是覆盖EditText
的onPreKeyIme()
,但是LibGDX TextField
与Android的无关,并且没有连接.
FINAL EDIT
As LibGDX authors said - there's no way to retrieve this in a normal way cause the back button is proccessed outside of application while it's pressed when keyboard is visible. Android solution is to override EditText
's onPreKeyIme()
but LibGDX TextField
has nothing to do with Android's one and there's no connection.
如果有人可以为这个问题提供解决方案,我将不胜感激.
If there's anyone that could point any solution to this problem, I'd be grateful.
推荐答案
使用本教程重写GDX Launcher类: https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx
Rewrite your GDX Launcher class using this tutorial:https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx
然后,您将拥有RelativeLayout,因此您可以覆盖dispatchKeyEventPreIme()方法它将在事件发送到IME之前捕获事件;)
Then, you'll have your RelativeLayout so you can override your dispatchKeyEventPreIme() methodwhich will catch events before they're sent to the IME ;)
RelativeLayout layout = new RelativeLayout(this) {
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
// back pressed }
}
return super.dispatchKeyEventPreIme(event);
}
};
这篇关于LibGDX-如何在可见的Android键盘中捕获TextField内部的后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!