【发布时间】:2020-05-29 17:02:51
【问题描述】:
是否可以将 AdMob 横幅广告添加到资产文件夹 HTML 文件中? 我使用 recyclerview 为列表和资产文件夹制作了一本电子书,其中包含包含相关标题内容的 HTML 文件。我在 Activity_Main 中添加了一个 AdMob 横幅,其中显示了标题列表。而现在想在 assets 文件夹中的内容中添加一个类似的横幅广告。
PS 这是我构建的第一个应用程序,通过 Youtube 和 Stackoverflow 等其他网站学习
公共类 MainActivity 扩展 AppCompatActivity {
private static final String TAG = "MainActivity";
private Context mContext;
ArrayList<String> titleArrayList;
private RecyclerView mRecyclerView;
AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when the user is about to return
// to the app after tapping on an ad.
}
});
mContext = MainActivity.this;
titleArrayList = new ArrayList<String>();
titleArrayList.add(Constants.Title_1);
titleArrayList.add(Constants.Title_2);
titleArrayList.add(Constants.Title_3);
titleArrayList.add(Constants.Title_4);
titleArrayList.add(Constants.Title_5);
mRecyclerView = (RecyclerView) findViewById(R.id.title_layout_RecyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
TitleAdapter adapter = new TitleAdapter(mContext, titleArrayList, new CustomItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Intent desIntent = new Intent(mContext,DescriptionActivity.class);
desIntent.putExtra("titles",titleArrayList.get(position));
startActivity(desIntent);
Toast.makeText(mContext, "clicked"+titleArrayList.get(position), Toast.LENGTH_SHORT).show();
}
});
mRecyclerView.setAdapter(adapter);
}
}
【问题讨论】:
标签: java android android-studio admob assets