我正在尝试在我的 libgdx 游戏底部显示横幅广告。游戏编译并运行良好,但没有广告显示。我如何检查广告设置是否正确以及我可以在我的代码中更改哪些内容以显示广告。
public class AndroidLauncher extends AndroidApplication {
private AdView adView;
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(params);
View gameView=initializeForView(new BuckyRun(), config);
RelativeLayout.LayoutParams gameViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
gameViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
gameViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
gameView.setLayoutParams(gameViewParams);
layout.addView(gameView);
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("secret");
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adView.loadAd(adRequestBuilder.build());
RelativeLayout.LayoutParams topParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
topParams.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
topParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
layout.addView(adView, topParams);
adView.setBackgroundColor(android.graphics.Color.TRANSPARENT);
setContentView(layout);
}
@Override
protected void onResume() {
super.onResume();
adView.resume();
}
@Override
protected void onPause() {
super.onPause();
adView.pause();
}
@Override
protected void onDestroy() {
super.onDestroy();
adView.destroy();
}
最佳答案
The Ad Unit ID will take time 12 hours to come live on google.
至此,使用 App ID 进行测试以初始化 SDK:ca-app-pub-3940256099942544~3347511713。
关于java - 如何让 ADmob 横幅广告显示在 Libgdx 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48684285/