我正在注册弹出视图如下:
GamesClient gamesClient = Games.getGamesClient(activity, googleSignInAccount);
gamesClient.setViewForPopups(getWindow().getDecorView().findViewById(android.R.id.content));
在主要活动中,但是当从全屏片段对话框解锁成就时,没有显示弹出窗口,但在活动中,它显示正确。
请帮助显示片段上的弹出窗口。
我试图从片段中注册弹出视图,但没有任何反应。
什么都不做,删除你的
setViewForPopups
电话。没必要。
试试这个
<FrameLayout
android:id="@+id/container_pop_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp" />
GamesClient gamesClient = Games.getGamesClient(MainActivity.this,
GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(R.id.container_pop_up));
Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.unlock(getString(R.string.achievement_example));
不需要 xml 参考。使用这个:
GamesClient gamesClient = Games.getGamesClient(this, Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(this)));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);