[Android] 可能不會向所有使用者顯示無邊框畫面

自 Android 15 起,目標版本為 SDK 35 的應用程式會預設採用無邊框畫面。開發人員應妥善處理插邊,確保此類應用程式能在 Android 15 以上版本中正確顯示。請調查這個問題,並花點時間測試無邊框畫面,然後視需要更新應用程式。如要回溯相容,您也可以呼叫 enableEdgeToEdge() (適用於 Kotlin) 或 EdgeToEdge.enable() (適用於 Java)。

以下是為了修復 Google AdMob 的「已淘汰的無邊框 API」警告所做的所有變更:

修改摘要

檔案變更內容
build.gradle新增 androidx.activity:activity:1.10.1 依賴項
MainTabActivity.java加入 EdgeToEdge.enable(this)
ActivityCategoryKt.kt加入 enableEdgeToEdge() (Kotlin 擴充函式)
SettingsActivity.java加入 EdgeToEdge.enable(this)
activity_main_tab.xmlfitsSystemWindows 從廣告容器移至根 CoordinatorLayout

build.gradle

 dependencies {
    implementation 'androidx.activity:activity:1.10.1'

ActivityCategoryKt.kt

     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         enableEdgeToEdge()
         setContentView(R.layout.fragment_list)

activity_main_tab.xml

@@ -7,6 +7,7 @@
     android:id="@+id/main_content"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:fitsSystemWindows="true"
     tools:context=".MainTabActivity">

     <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar"
@@ -17,8 +18,7 @@
         <FrameLayout android:id="@+id/ad_view_container"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_gravity="center_horizontal"
-            android:fitsSystemWindows="true"  />
+            android:layout_gravity="center_horizontal" />

         <com.google.android.material.tabs.TabLayout android:id="@+id/tabs"
             android:layout_width="match_parent"

關鍵點

  1. EdgeToEdge.enable() 必須在 setContentView() 之前呼叫,這樣 AndroidX Activity 庫會自動處理系統列(狀態列、導航列)的插邊,實現回溯相容
  2. 佈局調整:將 fitsSystemWindows="true" 從 ad_view_container 移到根 CoordinatorLayout,讓系統插邊在正確的層級被處理,廣告不會被系統列遮擋

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *