Skip to content

Commit 4bebaff

Browse files
Add small home banner native ad layout
1 parent 4e298ce commit 4bebaff

File tree

8 files changed

+68
-12
lines changed

8 files changed

+68
-12
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ads/managers/NativeAdLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class NativeAdLoader {
2525

2626
public static void load(@NonNull Context context, @NonNull ViewGroup container) {
27-
load(context, container, R.layout.native_ad);
27+
load(context, container, R.layout.large_home_banner_native_ad);
2828
}
2929

3030
public static void load(@NonNull Context context, @NonNull ViewGroup container, @LayoutRes int layoutRes) {

app/src/main/java/com/d4rk/androidtutorials/java/ads/views/NativeAdBannerView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
public class NativeAdBannerView extends FrameLayout {
2121

22-
private int layoutRes = R.layout.native_ad;
22+
private int layoutRes = R.layout.large_home_banner_native_ad;
2323

2424
public NativeAdBannerView(@NonNull Context context) {
2525
super(context);
@@ -39,7 +39,7 @@ public NativeAdBannerView(@NonNull Context context, @Nullable AttributeSet attrs
3939
private void init(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
4040
if (attrs != null) {
4141
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NativeAdBannerView, defStyleAttr, 0);
42-
layoutRes = a.getResourceId(R.styleable.NativeAdBannerView_nativeAdLayout, R.layout.native_ad);
42+
layoutRes = a.getResourceId(R.styleable.NativeAdBannerView_nativeAdLayout, R.layout.large_home_banner_native_ad);
4343
a.recycle();
4444
}
4545
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
android:id="@+id/ad_view"
5858
android:layout_width="match_parent"
5959
android:layout_height="match_parent"
60-
app:nativeAdLayout="@layout/native_ad" />
60+
app:nativeAdLayout="@layout/large_home_banner_native_ad" />
6161
</FrameLayout>
6262

6363
<com.google.android.material.bottomnavigation.BottomNavigationView

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
android:layout_height="wrap_content"
127127
android:layout_marginTop="16dp"
128128
android:layout_marginBottom="16dp"
129-
app:nativeAdLayout="@layout/native_ad" />
129+
app:nativeAdLayout="@layout/large_home_banner_native_ad" />
130130
</androidx.appcompat.widget.LinearLayoutCompat>
131131
</me.zhanghai.android.fastscroll.FastScrollScrollView>
132132
</androidx.constraintlayout.widget.ConstraintLayout>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
android:layout_height="wrap_content"
175175
android:layout_marginTop="16dp"
176176
app:layout_constraintTop_toBottomOf="@id/card_view_about"
177-
app:nativeAdLayout="@layout/native_ad" />
177+
app:nativeAdLayout="@layout/large_home_banner_native_ad" />
178178

179179
<com.airbnb.lottie.LottieAnimationView
180180
android:id="@+id/animation_about"

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
android:layout_marginHorizontal="16dp"
151151
android:layout_marginTop="16dp"
152152
android:layout_marginBottom="16dp"
153-
app:nativeAdLayout="@layout/native_ad" />
153+
app:nativeAdLayout="@layout/large_home_banner_native_ad" />
154154

155155
<androidx.appcompat.widget.LinearLayoutCompat
156156
android:id="@+id/other_apps_section"
@@ -188,7 +188,8 @@
188188
android:layout_width="match_parent"
189189
android:layout_height="wrap_content"
190190
android:layout_marginHorizontal="16dp"
191-
android:layout_marginBottom="16dp">
191+
android:layout_marginBottom="0dp"
192+
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewTopRounded">
192193

193194
<androidx.appcompat.widget.LinearLayoutCompat
194195
android:layout_width="match_parent"
@@ -215,13 +216,22 @@
215216
</androidx.appcompat.widget.LinearLayoutCompat>
216217
</com.google.android.material.card.MaterialCardView>
217218

218-
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
219-
android:id="@+id/small_banner_ad"
219+
<com.google.android.material.card.MaterialCardView
220+
android:id="@+id/ad_card"
221+
style="@style/Widget.Material3.CardView.Outlined"
220222
android:layout_width="match_parent"
221223
android:layout_height="wrap_content"
222224
android:layout_marginHorizontal="16dp"
223-
android:layout_marginTop="16dp"
224-
app:nativeAdLayout="@layout/native_ad" />
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>
225235

226236
<com.airbnb.lottie.LottieAnimationView
227237
android:id="@+id/learningAnimation"
File renamed without changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
<LinearLayout
8+
android:layout_width="match_parent"
9+
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" />
19+
20+
<LinearLayout
21+
android:layout_width="0dp"
22+
android:layout_height="wrap_content"
23+
android:layout_weight="1"
24+
android:orientation="vertical">
25+
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" />
31+
32+
<TextView
33+
android:id="@+id/ad_body"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
37+
</LinearLayout>
38+
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>
45+
46+
</com.google.android.gms.ads.nativead.NativeAdView>

0 commit comments

Comments
 (0)