android app 在api 35後 layout padding失效問題
這真是災難,google 發出聲明 2025/8/31前要更新到api 35.
但api35 就是會有這問題.導致app layout全部亂掉 .
https://developer.android.com/develop/ui/views/layout/edge-to-edge
To provide users with a safe and secure experience, Google Play requires all apps to meet target API level requirements.From Aug 31, 2025, if your target API level is not within 1 year of the latest Android release, you won't be able to update your app.
不升級還不行,舊的app沒更新的在android 15機器上都亂了,還導致appbar被蓋掉,內容被appbar佔住.
google 亂搞也不是第一次.
煩!
Apps targeting Android 15 will be forced into edge-to-edge mode
以 Android 15 (API 級別 35) 為目標版本的應用程式,且在 Android 15 裝置上是從邊到邊顯示。不過,由於 Android 15 強制執行無邊框功能,許多元素現在都會被狀態列、3 鍵導覽列或螢幕凹口隱藏。隱藏的 UI 包括 Material 2 頂端應用程式列、浮動動作按鈕和清單項目。
Android 15(預計是 Android U)對 UI 元件(特別是沉浸式狀態列、NavigationBar、WindowInsets 等)有一些調整,導致許多 App 出現 AppBar
錯位、重疊或 padding 不正確的問題,這種現象在使用 WindowInsetsController
或 Edge-to-Edge
佈局的 App 上尤其常見。
✅ 問題可能的成因:
-WindowInsets 行為改變(例如 fitSystemWindows 已不建議使用)。
-狀態列/導航列高度回傳不同或為 0。
-AppBarLayout 或 Toolbar 沒有正確處理 insets(paddingTop、marginTop)。
-App Theme 沒設好 Edge-to-Edge 支援(例如透明 statusBar 但未補上 inset padding)。
如果你遇到 android:padding="10dp"
在 Android 14/15 無效,就是因為 WindowInsets 影響 layout 運作。
Everything around status bars, toolbars, fullscreen, cutouts, insets, .... has been such a painful experience.
在 Android 14 或 15 實機(或模擬器)上卻完全 沒有效果(也就是 padding 被吃掉了),可能出現在 root layout 或 AppBar、Fragment Container 等處。
https://developer.android.com/about/versions/15/behavior-changes-15?hl=zh-tw
https://stackoverflow.com/questions/11816274/padding-not-working-android
https://stackoverflow.com/questions/78832459/how-to-preserve-the-space-of-the-status-bar-android-15
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActivityTransitions">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="27">shortEdges</item>
<item name="android:enforceNavigationBarContrast" tools:targetApi="29">false</item>
<item name="android:enforceStatusBarContrast" tools:targetApi="29">false</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">true</item>
</style>
檢查你的styles.xml
故:當目標 SDK 版本:您的 targetSdk 是 35 (Android 15)目前的主題設定:使用 Theme.AppCompat.Light.DarkActionBar,沒有處理 edge-to-edge
佈局問題:內容會與系統 UI (狀態列、導航列) 重疊
把所有 android:padding="10dp"
替換成:
android:layout_margin="10dp"
但這只是把padding問題補上.
狀態列系統底部導覽列顏色問題 ㄧ片白問題,如下圖:
解法需參考:https://blog.csdn.net/weixin_45576723/article/details/144628883
留言
張貼留言