Skip to content

Commit 6c7a095

Browse files
Refine native ad layouts and share attribution label
1 parent 4bebaff commit 6c7a095

File tree

6 files changed

+74
-49
lines changed

6 files changed

+74
-49
lines changed

AGENTS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ You are an experienced Android app developer.
1616

1717
## Testing
1818
- Run `./gradlew test` before committing changes.
19+
20+
## Native ads
21+
- 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.
22+
- Use the shared `@layout/ad_attribution` snippet for displaying the ad attribution text.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
3+
<solid android:color="@android:color/transparent" />
4+
<stroke android:width="1dp" android:color="?attr/colorPrimary" />
5+
<corners android:radius="4dp" />
6+
</shape>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/ad_attribution"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:background="@drawable/bg_ad_attribution"
7+
android:paddingHorizontal="4dp"
8+
android:paddingVertical="2dp"
9+
android:text="@string/ad"
10+
android:textColor="?attr/colorPrimary"
11+
android:textAppearance="@style/TextAppearance.Material3.LabelSmall" />

app/src/main/res/layout/fragment_home.xml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,11 @@
216216
</androidx.appcompat.widget.LinearLayoutCompat>
217217
</com.google.android.material.card.MaterialCardView>
218218

219-
<com.google.android.material.card.MaterialCardView
220-
android:id="@+id/ad_card"
221-
style="@style/Widget.Material3.CardView.Outlined"
219+
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
220+
android:id="@+id/small_banner_ad"
222221
android:layout_width="match_parent"
223222
android:layout_height="wrap_content"
224-
android:layout_marginHorizontal="16dp"
225-
android:layout_marginTop="0dp"
226-
android:layout_marginBottom="16dp"
227-
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewBottomRounded">
228-
229-
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
230-
android:id="@+id/small_banner_ad"
231-
android:layout_width="match_parent"
232-
android:layout_height="wrap_content"
233-
app:nativeAdLayout="@layout/small_home_banner_native_ad" />
234-
</com.google.android.material.card.MaterialCardView>
223+
app:nativeAdLayout="@layout/small_home_banner_native_ad" />
235224

236225
<com.airbnb.lottie.LottieAnimationView
237226
android:id="@+id/learningAnimation"

app/src/main/res/layout/large_home_banner_native_ad.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
android:layout_margin="16dp"
1717
android:orientation="vertical">
1818

19-
<TextView
20-
android:id="@+id/ad_attribution"
21-
android:layout_width="wrap_content"
22-
android:layout_height="wrap_content"
23-
android:text="@string/ad"
24-
android:textAppearance="@style/TextAppearance.Material3.LabelSmall" />
19+
<include layout="@layout/ad_attribution" />
2520

2621
<com.google.android.material.card.MaterialCardView
2722
style="@style/Widget.Material3.CardView.Filled"

app/src/main/res/layout/small_home_banner_native_ad.xml

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,63 @@
44
android:layout_width="match_parent"
55
android:layout_height="wrap_content">
66

7-
<LinearLayout
7+
<com.google.android.material.card.MaterialCardView
8+
android:id="@+id/ad_card"
9+
style="@style/Widget.Material3.CardView.Outlined"
810
android:layout_width="match_parent"
911
android:layout_height="wrap_content"
10-
android:orientation="horizontal"
11-
android:gravity="center_vertical"
12-
android:padding="16dp">
13-
14-
<ImageView
15-
android:id="@+id/ad_app_icon"
16-
android:layout_width="40dp"
17-
android:layout_height="40dp"
18-
android:layout_marginEnd="16dp" />
12+
android:layout_marginHorizontal="16dp"
13+
android:layout_marginTop="2dp"
14+
android:layout_marginBottom="16dp"
15+
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewBottomRounded">
1916

2017
<LinearLayout
21-
android:layout_width="0dp"
18+
android:layout_width="match_parent"
2219
android:layout_height="wrap_content"
23-
android:layout_weight="1"
24-
android:orientation="vertical">
20+
android:orientation="vertical"
21+
android:padding="16dp">
2522

26-
<TextView
27-
android:id="@+id/ad_headline"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
23+
<include layout="@layout/ad_attribution" />
3124

32-
<TextView
33-
android:id="@+id/ad_body"
34-
android:layout_width="wrap_content"
25+
<LinearLayout
26+
android:layout_width="match_parent"
3527
android:layout_height="wrap_content"
36-
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
37-
</LinearLayout>
28+
android:layout_marginTop="8dp"
29+
android:gravity="center_vertical"
30+
android:orientation="horizontal">
31+
32+
<ImageView
33+
android:id="@+id/ad_app_icon"
34+
android:layout_width="40dp"
35+
android:layout_height="40dp"
36+
android:layout_marginEnd="16dp" />
3837

39-
<com.google.android.material.button.MaterialButton
40-
android:id="@+id/ad_call_to_action"
41-
style="@style/Widget.Material3.Button.TextButton"
42-
android:layout_width="wrap_content"
43-
android:layout_height="wrap_content" />
44-
</LinearLayout>
38+
<LinearLayout
39+
android:layout_width="0dp"
40+
android:layout_height="wrap_content"
41+
android:layout_weight="1"
42+
android:orientation="vertical">
43+
44+
<TextView
45+
android:id="@+id/ad_headline"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
49+
50+
<TextView
51+
android:id="@+id/ad_body"
52+
android:layout_width="wrap_content"
53+
android:layout_height="wrap_content"
54+
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
55+
</LinearLayout>
56+
57+
<com.google.android.material.button.MaterialButton
58+
android:id="@+id/ad_call_to_action"
59+
style="@style/Widget.Material3.Button.TextButton"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content" />
62+
</LinearLayout>
63+
</LinearLayout>
64+
</com.google.android.material.card.MaterialCardView>
4565

4666
</com.google.android.gms.ads.nativead.NativeAdView>

0 commit comments

Comments
 (0)