调用Games.Achievements.unlock时不显示弹出窗口

问题描述 投票:11回答:3

我目前的Android游戏采用了BaseGameActivity。

我的游戏采用了成就,在需要时可以解锁。

但是,我并不总是看到与解锁事件相关的PopUps。

我知道只有在你第一次解锁成就时才会出现弹出窗口。

一些弹出窗口显得很好,其他(从我游戏中的不同屏幕)永远不会出现。

我该怎么做以保证弹出窗口出现?

我有一种感觉它与此警告有关:

W/PopupManager(10725): You have not specified a View to use as content view for popups.

Falling back to the Activity content view which may not work properly in future versions
of the API. 
Use setViewForPopups() to set your content view.

我从我的弹出窗口中没有显示的活动中调用了setViewForPopups(),但我从未见过它们。

如何调用setViewForPopups()以便整个应用程序看到上面显示的WARNING消息?

android google-play-games
3个回答
6
投票

我通过使用以下代码找到了解决方案

Games.setViewForPopups(getApiClient(), getWindow().getDecorView().findViewById(android.R.id.content));

我可以弹出窗口显示。我现在有一个相关的问题。弹出窗口不会显示很长时间。

我认为这是因为我在此活动中有自定义动画。

有没有办法增加弹出窗口可见的时间?


4
投票

这对我有用。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    setContentView(R.layout.activity_main);

    // Create the Google API Client with access to Plus, Games and Drive
    // Also set the view for popups
    mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
            .setViewForPopups(findViewById(android.R.id.content))
            .build();

}

android.R.id.content为您提供视图的根元素,而无需知道其实际名称/类型/ ID。看看Get root view from current activity


4
投票

Games.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" />

并在您初始化AchievementsClient类对象的代码之后添加下一个代码

 GamesClient gamesClient = Games.getGamesClient(MainActivity.this, googleSignInAccount);
 gamesClient.setViewForPopups(findViewById(R.id.container_pop_up));

其中googleSignInAccount是GoogleSignInAccount's对象

© www.soinside.com 2019 - 2024. All rights reserved.