Java 如何在通知android上显示自定义布局
我想在通知中显示一个Java 如何在通知android上显示自定义布局,java,android,xml,admob,Java,Android,Xml,Admob,我想在通知中显示一个横幅广告,因此为了构建自定义通知,我使用了这些代码 RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.banner_ad); Notification customNotification = new NotificationCompat.Builder(this, "ChannelID") .setSmall
横幅
广告,因此为了构建自定义通知,我使用了这些代码
RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.banner_ad);
Notification customNotification = new NotificationCompat.Builder(this, "ChannelID")
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.build();
还有我的banner_ad.xml
code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/idAdViewNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_01"
/>
</RelativeLayout>
所以这里我的问题是,要加载这个广告,我必须通过java代码处理
AdView ID
。那么,如何将AdView的ID从xml映射到java中的AdView类呢。在构建自定义通知时,我如何才能访问idAdViewNotification
不要这样做,这是违反admob政策的OK thnx人,我甚至不知道@Hamaz