diff --git a/AGENTS.md b/AGENTS.md
index d4927bc7..9aa4f282 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -16,3 +16,8 @@ You are an experienced Android app developer.
## Testing
- Run `./gradlew test` before committing changes.
+
+## Native ads
+- Native ad XML layouts should wrap their content in a `MaterialCardView` with the ID `ad_card` using `@style/Widget.Material3.CardView.Outlined` and appropriate rounded corner overlays.
+- Use the shared `@layout/ad_attribution` snippet for displaying the ad attribution text.
+- Place the attribution include as the first child of the ad card and override its padding or text color attributes to fit each layout.
diff --git a/app/src/main/java/com/d4rk/androidtutorials/java/ads/managers/NativeAdLoader.java b/app/src/main/java/com/d4rk/androidtutorials/java/ads/managers/NativeAdLoader.java
index cc06a099..4fc4847f 100644
--- a/app/src/main/java/com/d4rk/androidtutorials/java/ads/managers/NativeAdLoader.java
+++ b/app/src/main/java/com/d4rk/androidtutorials/java/ads/managers/NativeAdLoader.java
@@ -24,7 +24,7 @@
public class NativeAdLoader {
public static void load(@NonNull Context context, @NonNull ViewGroup container) {
- load(context, container, R.layout.native_ad);
+ load(context, container, R.layout.large_home_banner_native_ad);
}
public static void load(@NonNull Context context, @NonNull ViewGroup container, @LayoutRes int layoutRes) {
@@ -58,7 +58,9 @@ private static void populateNativeAdView(@NonNull NativeAd nativeAd, @NonNull Na
adView.setHeadlineView(headlineView);
adView.setBodyView(bodyView);
adView.setCallToActionView(callToActionView);
- adView.setIconView(iconView);
+ if (iconView != null) {
+ adView.setIconView(iconView);
+ }
adView.setAdvertiserView(attributionView);
if (headlineView != null) {
diff --git a/app/src/main/java/com/d4rk/androidtutorials/java/ads/views/NativeAdBannerView.java b/app/src/main/java/com/d4rk/androidtutorials/java/ads/views/NativeAdBannerView.java
index 05e9bf3b..6f203d30 100644
--- a/app/src/main/java/com/d4rk/androidtutorials/java/ads/views/NativeAdBannerView.java
+++ b/app/src/main/java/com/d4rk/androidtutorials/java/ads/views/NativeAdBannerView.java
@@ -19,7 +19,7 @@
*/
public class NativeAdBannerView extends FrameLayout {
- private int layoutRes = R.layout.native_ad;
+ private int layoutRes = R.layout.large_home_banner_native_ad;
public NativeAdBannerView(@NonNull Context context) {
super(context);
@@ -39,7 +39,7 @@ public NativeAdBannerView(@NonNull Context context, @Nullable AttributeSet attrs
private void init(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NativeAdBannerView, defStyleAttr, 0);
- layoutRes = a.getResourceId(R.styleable.NativeAdBannerView_nativeAdLayout, R.layout.native_ad);
+ layoutRes = a.getResourceId(R.styleable.NativeAdBannerView_nativeAdLayout, R.layout.large_home_banner_native_ad);
a.recycle();
}
}
diff --git a/app/src/main/res/drawable/bg_ad_attribution.xml b/app/src/main/res/drawable/bg_ad_attribution.xml
new file mode 100644
index 00000000..8857889f
--- /dev/null
+++ b/app/src/main/res/drawable/bg_ad_attribution.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 9657d9fe..7d15a314 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -44,7 +44,7 @@
+ app:nativeAdLayout="@layout/bottom_app_bar_native_ad" />
+ app:nativeAdLayout="@layout/large_home_banner_native_ad" />
diff --git a/app/src/main/res/layout/ad_attribution.xml b/app/src/main/res/layout/ad_attribution.xml
new file mode 100644
index 00000000..25be5f02
--- /dev/null
+++ b/app/src/main/res/layout/ad_attribution.xml
@@ -0,0 +1,11 @@
+
+
diff --git a/app/src/main/res/layout/bottom_app_bar_native_ad.xml b/app/src/main/res/layout/bottom_app_bar_native_ad.xml
new file mode 100644
index 00000000..3a1b4571
--- /dev/null
+++ b/app/src/main/res/layout/bottom_app_bar_native_ad.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml
index f9662237..97bc9c11 100644
--- a/app/src/main/res/layout/fragment_about.xml
+++ b/app/src/main/res/layout/fragment_about.xml
@@ -174,7 +174,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/card_view_about"
- app:nativeAdLayout="@layout/native_ad" />
+ app:nativeAdLayout="@layout/large_home_banner_native_ad" />
+ app:nativeAdLayout="@layout/large_home_banner_native_ad" />
+ android:layout_marginBottom="0dp"
+ app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewTopRounded">
+ app:nativeAdLayout="@layout/small_home_banner_native_ad" />
-
+
-
-
-
-
+ android:orientation="vertical">
-
+
-
+
+
+
+
+
diff --git a/app/src/main/res/layout/small_home_banner_native_ad.xml b/app/src/main/res/layout/small_home_banner_native_ad.xml
new file mode 100644
index 00000000..7d7004a4
--- /dev/null
+++ b/app/src/main/res/layout/small_home_banner_native_ad.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+