Skip to content

Commit 2e78ece

Browse files
malandr2copybara-github
authored andcommitted
Fix API >= 35 layout for Banner examples
PiperOrigin-RevId: 852334874
1 parent 1278908 commit 2e78ece

File tree

19 files changed

+158
-13
lines changed

19 files changed

+158
-13
lines changed

java/admanager/BannerExample/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ dependencies {
2323
implementation 'androidx.appcompat:appcompat:1.2.0'
2424
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
2525
implementation 'com.google.android.gms:play-services-ads:24.9.0'
26+
implementation 'com.google.android.material:material:1.13.0'
2627
implementation 'com.google.android.ump:user-messaging-platform:4.0.0'
2728
}

java/admanager/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MyActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import android.widget.PopupMenu;
2626
import android.widget.Toast;
2727
import androidx.appcompat.app.AppCompatActivity;
28+
import androidx.core.graphics.Insets;
29+
import androidx.core.view.ViewCompat;
30+
import androidx.core.view.WindowInsetsCompat;
2831
import com.google.android.gms.ads.AdSize;
2932
import com.google.android.gms.ads.MobileAds;
3033
import com.google.android.gms.ads.RequestConfiguration;
@@ -55,8 +58,18 @@ public class MyActivity extends AppCompatActivity {
5558
protected void onCreate(Bundle savedInstanceState) {
5659
super.onCreate(savedInstanceState);
5760
setContentView(R.layout.activity_my);
61+
setSupportActionBar(findViewById(R.id.toolBar));
5862
adContainerView = findViewById(R.id.ad_view_container);
5963

64+
ViewCompat.setOnApplyWindowInsetsListener(
65+
findViewById(R.id.main),
66+
(view, insets) -> {
67+
Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
68+
view.setPadding(
69+
systemBarsInsets.left, 0, systemBarsInsets.right, systemBarsInsets.bottom);
70+
return insets;
71+
});
72+
6073
// Log the Mobile Ads SDK version.
6174
Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion());
6275

java/admanager/BannerExample/app/src/main/res/layout/activity_my.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
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+
android:id="@+id/main"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent">
67

8+
<com.google.android.material.appbar.AppBarLayout
9+
android:id="@+id/app_bar_layout"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:fitsSystemWindows="true"
13+
android:background="@color/colorPrimaryDark"
14+
app:layout_constraintTop_toTopOf="parent">
15+
16+
<com.google.android.material.appbar.MaterialToolbar
17+
android:id="@+id/toolBar"
18+
android:layout_width="match_parent"
19+
android:layout_height="?attr/actionBarSize"
20+
app:titleTextColor="@android:color/white"
21+
app:title="@string/app_name" />
22+
23+
</com.google.android.material.appbar.AppBarLayout>
24+
725
<FrameLayout
826
android:id="@+id/ad_view_container"
927
android:layout_width="0dp"
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+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<resources>
22

3-
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5-
<!-- Customize your theme here. -->
6-
</style>
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
710

811
</resources>

java/admob/BannerExample/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ dependencies {
2323
implementation 'androidx.appcompat:appcompat:1.2.0'
2424
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
2525
implementation 'com.google.android.gms:play-services-ads:24.9.0'
26+
implementation 'com.google.android.material:material:1.13.0'
2627
implementation 'com.google.android.ump:user-messaging-platform:4.0.0'
2728
}

java/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample/MyActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import android.widget.PopupMenu;
2626
import android.widget.Toast;
2727
import androidx.appcompat.app.AppCompatActivity;
28+
import androidx.core.graphics.Insets;
29+
import androidx.core.view.ViewCompat;
30+
import androidx.core.view.WindowInsetsCompat;
2831
import com.google.android.gms.ads.AdRequest;
2932
import com.google.android.gms.ads.AdSize;
3033
import com.google.android.gms.ads.AdView;
@@ -55,8 +58,18 @@ public class MyActivity extends AppCompatActivity {
5558
protected void onCreate(Bundle savedInstanceState) {
5659
super.onCreate(savedInstanceState);
5760
setContentView(R.layout.activity_my);
61+
setSupportActionBar(findViewById(R.id.toolBar));
5862
adContainerView = findViewById(R.id.ad_view_container);
5963

64+
ViewCompat.setOnApplyWindowInsetsListener(
65+
findViewById(R.id.main),
66+
(view, insets) -> {
67+
Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
68+
view.setPadding(
69+
systemBarsInsets.left, 0, systemBarsInsets.right, systemBarsInsets.bottom);
70+
return insets;
71+
});
72+
6073
// Log the Mobile Ads SDK version.
6174
Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion());
6275

java/admob/BannerExample/app/src/main/res/layout/activity_my.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
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+
android:id="@+id/main"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent">
67

8+
<com.google.android.material.appbar.AppBarLayout
9+
android:id="@+id/app_bar_layout"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:fitsSystemWindows="true"
13+
android:background="@color/colorPrimaryDark"
14+
app:layout_constraintTop_toTopOf="parent">
15+
16+
<com.google.android.material.appbar.MaterialToolbar
17+
android:id="@+id/toolBar"
18+
android:layout_width="match_parent"
19+
android:layout_height="?attr/actionBarSize"
20+
app:titleTextColor="@android:color/white"
21+
app:title="@string/app_name" />
22+
23+
</com.google.android.material.appbar.AppBarLayout>
24+
725
<FrameLayout
826
android:id="@+id/ad_view_container"
927
android:layout_width="0dp"
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+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<resources>
22

3-
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5-
<!-- Customize your theme here. -->
6-
</style>
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
710

811
</resources>

0 commit comments

Comments
 (0)