Skip to content

Commit da5093e

Browse files
Nicholas Ventimigliacopybara-github
authored andcommitted
Fix: UI Overlap in FullScreenNativeExample
PiperOrigin-RevId: 837193961
1 parent 8ea2709 commit da5093e

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
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" />

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,10 @@
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.WindowCompat;
16+
import androidx.core.view.WindowInsetsCompat;
1317
import androidx.fragment.app.FragmentManager;
1418
import com.google.android.gms.ads.AdListener;
1519
import com.google.android.gms.ads.AdLoader;
@@ -47,9 +51,22 @@ public NativeAd getNativeAd() {
4751
@Override
4852
protected void onCreate(Bundle savedInstanceState) {
4953
super.onCreate(savedInstanceState);
54+
55+
// Enable edge-to-edge display
56+
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
57+
5058
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
5159
setContentView(binding.getRoot());
5260

61+
// Apply insets to the root view to avoid overlap with system bars.
62+
ViewCompat.setOnApplyWindowInsetsListener(
63+
binding.fragmentContainerView,
64+
(v, windowInsets) -> {
65+
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
66+
v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
67+
return WindowInsetsCompat.CONSUMED;
68+
});
69+
5370
Log.d(TAG, "Google Mobile Ads SDK Version: " + MobileAds.getVersion());
5471

5572
googleMobileAdsConsentManager =
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<resources>
2-
3-
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
5-
<!-- Customize your theme here. -->
6-
</style>
7-
2+
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar" />
83
<style name="AppTheme.AdAttribution">
94
<item name="android:layout_width">wrap_content</item>
105
<item name="android:layout_height">wrap_content</item>
@@ -16,5 +11,4 @@
1611
<item name="android:width">15dp</item>
1712
<item name="android:height">15dp</item>
1813
</style>
19-
2014
</resources>

0 commit comments

Comments
 (0)