Skip to content

Commit 114be87

Browse files
malandr2copybara-github
authored andcommitted
Add support for API >= 35 layout
PiperOrigin-RevId: 840760624
1 parent 8ea2709 commit 114be87

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

java/admob/FullScreenNativeExample/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ dependencies {
2525
implementation 'androidx.appcompat:appcompat:1.7.0'
2626
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
2727
implementation 'com.google.android.gms:play-services-ads:24.8.0'
28+
implementation 'com.google.android.material:material:1.13.0'
2829
}

java/admob/FullScreenNativeExample/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
android:networkSecurityConfig="@xml/network_security_config"
1010
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:taskAffinity=""
12-
android:theme="@style/Theme.AppCompat.Light">
12+
android:theme="@style/AppTheme">
1313
<meta-data
1414
android:name="com.google.android.gms.ads.APPLICATION_ID"
1515
android:value="ca-app-pub-3940256099942544~3347511713" />
1616

1717
<activity
1818
android:name="com.google.example.gms.fullscreennativeexample.MainActivity"
19+
android:screenOrientation="sensorPortrait"
1920
android:exported="true">
2021
<intent-filter>
2122
<action android:name="android.intent.action.MAIN" />

java/admob/FullScreenNativeExample/app/src/main/java/com/google/example/gms/fullscreennativeexample/MainActivity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import android.widget.Toast;
1111
import androidx.annotation.NonNull;
1212
import androidx.appcompat.app.AppCompatActivity;
13+
import androidx.core.graphics.Insets;
14+
import androidx.core.view.ViewCompat;
15+
import androidx.core.view.WindowInsetsCompat;
1316
import androidx.fragment.app.FragmentManager;
1417
import com.google.android.gms.ads.AdListener;
1518
import com.google.android.gms.ads.AdLoader;
@@ -49,6 +52,20 @@ protected void onCreate(Bundle savedInstanceState) {
4952
super.onCreate(savedInstanceState);
5053
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
5154
setContentView(binding.getRoot());
55+
setSupportActionBar(binding.toolBar);
56+
57+
ViewCompat.setOnApplyWindowInsetsListener(
58+
binding.fragmentContainerView,
59+
(view, insets) -> {
60+
Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
61+
// Apply only the bottom inset.
62+
view.setPadding(
63+
view.getPaddingLeft(),
64+
view.getPaddingTop(),
65+
view.getPaddingRight(),
66+
systemBarsInsets.bottom);
67+
return insets;
68+
});
5269

5370
Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion());
5471

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
<androidx.fragment.app.FragmentContainerView
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
23
xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:id="@+id/fragment_container_view"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
6-
android:name="com.google.example.gms.fullscreennativeexample.MainFragment" />
7+
android:orientation="vertical">
8+
9+
<com.google.android.material.appbar.AppBarLayout
10+
android:id="@+id/app_bar_layout"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:fitsSystemWindows="true"
14+
android:background="@color/material_dynamic_primary0"
15+
>
16+
17+
<com.google.android.material.appbar.MaterialToolbar
18+
android:id="@+id/toolBar"
19+
android:layout_width="match_parent"
20+
android:layout_height="?attr/actionBarSize"
21+
app:titleTextColor="@android:color/white"
22+
app:title="@string/app_name" />
23+
24+
</com.google.android.material.appbar.AppBarLayout>
25+
26+
<androidx.fragment.app.FragmentContainerView
27+
android:id="@+id/fragment_container_view"
28+
android:layout_width="match_parent"
29+
android:layout_height="match_parent"
30+
android:name="com.google.example.gms.fullscreennativeexample.MainFragment"
31+
/>
32+
33+
</LinearLayout>
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<resources>
22

3-
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
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+
</style>
77

8-
<style name="AppTheme.AdAttribution">
9-
<item name="android:layout_width">wrap_content</item>
10-
<item name="android:layout_height">wrap_content</item>
11-
<item name="android:layout_gravity">left</item>
12-
<item name="android:textColor">#FFFFFF</item>
13-
<item name="android:textSize">12sp</item>
14-
<item name="android:text">@string/ad_attribution</item>
15-
<item name="android:background">#FFCC66</item>
16-
<item name="android:width">15dp</item>
17-
<item name="android:height">15dp</item>
18-
</style>
8+
<style name="AppTheme.AdAttribution">
9+
<item name="android:layout_width">wrap_content</item>
10+
<item name="android:layout_height">wrap_content</item>
11+
<item name="android:layout_gravity">left</item>
12+
<item name="android:textColor">#FFFFFF</item>
13+
<item name="android:textSize">12sp</item>
14+
<item name="android:text">@string/ad_attribution</item>
15+
<item name="android:background">#FFCC66</item>
16+
<item name="android:width">15dp</item>
17+
<item name="android:height">15dp</item>
18+
</style>
1919

2020
</resources>

0 commit comments

Comments
 (0)