java - 更改原生 Admob 样式
问题描述
我曾经在我的应用程序中有一个原生广告,我使用以下代码来创建它并设置它的样式:
MobileAds.initialize( itemView.getContext(), AppConstants.APP_ADS_ID );
AdLoader adLoader = new AdLoader.Builder( itemView.getContext(), itemView.getContext().getResources().getString( R.string.Native_Ads ) )
.forUnifiedNativeAd( unifiedNativeAd -> {
NativeTemplateStyle styles = new
NativeTemplateStyle.Builder().withMainBackgroundColor( new ColorDrawable( itemView.getContext().getResources().getColor( R.color.colorWhite ) ) ).build();
TemplateView template = itemView.findViewById( R.id.my_template );
template.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 300 ) );
template.setStyles( styles );
template.setNativeAd( unifiedNativeAd );
} )
.build();
adLoader.loadAd( new AdRequest.Builder().build() );
但是,forUnifiedNativeAd
已弃用,并且根据我需要使用的文档:
AdLoader adLoader = new AdLoader.Builder(context, "ca-app-pub-3940256099942544/2247696110")
.forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
@Override
public void onNativeAdLoaded(NativeAd NativeAd) {
// Show the ad.
}
})
.withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(LoadAdError adError) {
// Handle the failure by logging, altering the UI, and so on.
}
})
.withNativeAdOptions(new NativeAdOptions.Builder()
// Methods in the NativeAdOptions.Builder class can be
// used here to specify individual options settings.
.build())
.build();
关于如何使用新方法保持风格的任何想法?
谢谢
解决方案
推荐阅读
- react-native - Expo 图像选择器将选定的图像传递给 API
- meshlab - PyMeshLab - MLS 投影 APSS - 循环的当前和代理网格 ID
- powershell - 如何正确验证powershell中的参数?
- python - 匹配共享相同类型数据的两列的有效方法
- node.js - 使用 webdriverIO,有没有办法自动悬停在一个元素上(建立在一层之上),因此无法找到该元素的位置
- flutter - 无法放大和移动框架内的图像
- qt - 应用删除文本后,组合框的下拉菜单不会调整大小
- wordpress - 如果未选择 XX 国家并且结帐页面上的购物车包含 WooCommerce 中的特定产品,则禁用下订单按钮并显示消息
- loops - 以小于一个的步骤重复
- python - 使用 django-rest-framework 处理会话