如何在 libGDX 中显示 Google 游戏服务弹出窗口?

How to display Google Game Services popups in libGDX?

我一直在尝试将 setPopUpView() 添加到我的 LibGDX 项目中,但它没有显示。这是我的代码。

 private void signInSilently() {
        mGoogleSignInClient.silentSignIn().addOnCompleteListener(this,
                new OnCompleteListener<GoogleSignInAccount>() {
                    @Override
                    public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                        if (task.isSuccessful()) {
                            GoogleSignInAccount signedInAccount = task.getResult();
                            GamesClient gamesClient = Games.getGamesClient(AndroidLauncher.this, signedInAccount);
                            View view = new View(AndroidLauncher.this);
                            gamesClient.setGravityForPopups(Gravity.TOP);
                            gamesClient.setViewForPopups(view);
                            onConnected(task.getResult());
                            Log.d(TAG, "signInSilently(): success");
                        } else {
                            onDisconnected();
                            Log.d(TAG, "signInSilently(): failure", task.getException());
                        }
                    }
                });
    }

您应该从 AndroidLauncher activity 中检索 View:

GamesClient gamesClient = Games.getGamesClient(AndroidLauncher.this, signedInAccount);
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
gamesClient.setViewForPopups(((AndroidGraphics) AndroidLauncher.this.getGraphics()).getView());
// or, which is the same thing
// gamesClient.setViewForPopups(((AndroidGraphics) Gdx.graphics).getView());

您可能希望将这三行代码放在 onConnected() 方法中。