2017-02-21 14 views
0

我正在創建一個libGDX框架的Android遊戲。 我的設置屏幕是通過scene2d實現的。 我通過實現一個inputProcessorAdapter類來處理後退按鈕單擊事件。將它和Stage添加到InputMultiplexer進行輸入處理。libgdx輸入處理後,通過點擊adView打開的網頁支持不工作

一切正常除了點擊屏幕底部的廣告後,然後從谷歌廣告網頁返回到屏幕。返回鍵不再可以被inputProcessorAdapter捕獲。當舞臺的Textfield集中時,鍵盤也不再顯示。 以下是我的輸入處理代碼。

inputProcessor = new InputProcessorAdapter() { 
    @Override 
    public boolean keyDown(int keycode) { 
     if (keycode == Input.Keys.BACK) { 
      // Go back to main menu 
      stage.unfocusAll(); 
      Gdx.input.setOnscreenKeyboardVisible(false); 
      SettingScreen.this.game.setScreen(new MainMenuScreen(SettingScreen.this.game)); 
     } 
     return false; 
    } 
}; 

InputMultiplexer multiplexer = new InputMultiplexer(); 
multiplexer.addProcessor(inputProcessor); 
multiplexer.addProcessor(stage); 
Gdx.input.setInputProcessor(multiplexer); 

等待您的答案或建議。

回答

0

您應該將setInputProcessor調用後添加

Gdx.input.setCatchBackKey(true); 

所以整個代碼看起來應該像

... 
Gdx.input.setInputProcessor(multiplexer); 
Gdx.input.setCatchBackKey(true); 
... 
+0

非常感謝您的早期回答。我試過你的解決方案,但它仍然無法正常工作。實際上,我從頭開始在libgdx遊戲類的create()方法中添加了'Gdx.input.setCatchBackKey(true);'。 – go3boy

0

最後,我找到了解決方案通過在官方論壇網站主題的啓發。 Lifecicle messed up by Admob

下面是我的解決方案代碼。

adView.setAdListener(new AdListener() { 
     @Override 
     public void onAdClosed() { 
      super.onAdClosed(); 
      gameView.requestFocus(); 
     } 
    }); 
相關問題