Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 484a32a

Browse files
Merge pull request #145 from MihaiCristianCondrea/codex/create-native-ad-for-support-screen
feat: add support screen native ad and banner
2 parents a3480c0 + 51451da commit 484a32a

File tree

3 files changed

+95
-5
lines changed

3 files changed

+95
-5
lines changed

‎app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/support/SupportActivity.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ protected void onCreate(Bundle savedInstanceState) {
3030
supportViewModel = new ViewModelProvider(this).get(SupportViewModel.class);
3131

3232
AdRequest adRequest = supportViewModel.initMobileAds();
33-
binding.largeBannerAd.loadAd(adRequest);
33+
binding.supportNativeAd.loadAd(adRequest);
34+
binding.bannerAdView.loadAd(adRequest);
3435

3536
binding.buttonWebAd.setOnClickListener(v ->
3637
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://bit.ly/3p8bpjj"))));

‎app/src/main/res/layout/activity_support.xml‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:ads="http://schemas.android.com/apk/res-auto"
45
android:id="@+id/container"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent">
@@ -29,7 +30,8 @@
2930
style="@style/Widget.Material3.CardView.Outlined"
3031
android:layout_width="match_parent"
3132
android:layout_height="wrap_content"
32-
android:layout_margin="24dp">
33+
android:layout_margin="24dp"
34+
app:cardCornerRadius="24dp">
3335

3436
<androidx.appcompat.widget.LinearLayoutCompat
3537
android:layout_width="match_parent"
@@ -121,12 +123,24 @@
121123
app:layout_rowWeight="1" />
122124

123125
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
124-
android:id="@+id/large_banner_ad"
126+
android:id="@+id/support_native_ad"
125127
android:layout_width="match_parent"
126128
android:layout_height="wrap_content"
129+
android:layout_marginStart="24dp"
130+
android:layout_marginTop="16dp"
131+
android:layout_marginEnd="24dp"
132+
app:nativeAdLayout="@layout/ad_support" />
133+
134+
<com.google.android.gms.ads.AdView
135+
android:id="@+id/banner_ad_view"
136+
android:layout_width="match_parent"
137+
android:layout_height="wrap_content"
138+
android:layout_marginStart="24dp"
127139
android:layout_marginTop="16dp"
128-
android:layout_marginBottom="16dp"
129-
app:nativeAdLayout="@layout/ad_home_banner_large" />
140+
android:layout_marginEnd="24dp"
141+
android:layout_marginBottom="24dp"
142+
ads:adSize="FULL_BANNER"
143+
ads:adUnitId="@string/ad_banner_unit_id" />
130144
</androidx.appcompat.widget.LinearLayoutCompat>
131145
</me.zhanghai.android.fastscroll.FastScrollScrollView>
132146
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content">
6+
7+
<com.google.android.material.card.MaterialCardView
8+
android:id="@+id/ad_card"
9+
style="@style/Widget.Material3.CardView.Outlined"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
app:cardCornerRadius="24dp">
13+
14+
<LinearLayout
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:orientation="vertical"
18+
android:padding="16dp">
19+
20+
<include layout="@layout/ad_attribution" />
21+
22+
<LinearLayout
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:layout_marginTop="8dp"
26+
android:gravity="center_vertical"
27+
android:orientation="horizontal">
28+
29+
<ImageView
30+
android:id="@+id/ad_app_icon"
31+
android:layout_width="40dp"
32+
android:layout_height="40dp"
33+
android:contentDescription="@null" />
34+
35+
<TextView
36+
android:id="@+id/ad_headline"
37+
android:layout_width="0dp"
38+
android:layout_height="wrap_content"
39+
android:layout_marginStart="8dp"
40+
android:layout_weight="1"
41+
android:ellipsize="end"
42+
android:maxLines="1"
43+
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
44+
45+
<com.google.android.material.button.MaterialButton
46+
android:id="@+id/ad_call_to_action"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:layout_marginStart="8dp" />
50+
</LinearLayout>
51+
52+
<com.google.android.material.card.MaterialCardView
53+
android:id="@+id/media_card"
54+
style="@style/Widget.Material3.CardView.Filled"
55+
android:layout_width="match_parent"
56+
android:layout_height="180dp"
57+
android:layout_marginTop="8dp"
58+
android:layout_marginBottom="8dp"
59+
app:cardCornerRadius="12dp">
60+
61+
<com.google.android.gms.ads.nativead.MediaView
62+
android:id="@+id/ad_media"
63+
android:layout_width="match_parent"
64+
android:layout_height="match_parent"
65+
android:scaleType="centerCrop" />
66+
</com.google.android.material.card.MaterialCardView>
67+
68+
<TextView
69+
android:id="@+id/ad_body"
70+
android:layout_width="match_parent"
71+
android:layout_height="wrap_content"
72+
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
73+
</LinearLayout>
74+
</com.google.android.material.card.MaterialCardView>
75+
</com.google.android.gms.ads.nativead.NativeAdView>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /