Last Updated on 2025-11-22 by william
Google 最近強制所有 Android APP 開發 Target 必須改為 35 或以上,否則就不讓活。根據官方建議,程式需要用到 Insets 這個 API。

因為我自己不是很專業的 Android 開發者,一開始就中招了,沒認真看官方建議,直接把 Target 改為 35 後就提交上陣。為何我敢這樣做,因為我的手機是 Android 14 ,不會受影響;直到同事哇哇叫,說 APP 改版後,他手機 Android 15 出現重疊問題。
總歸一句話,我應該用 pixel 的
照著官方說法,我試了幾次,解決方式如下(Java):
// activity,使用 android.R.id.content 取得 view (通用)
View view = findViewById(android.R.id.content);
xxx.setView(activity,view);
// xxx
public static void setView(Activity act,View view){
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) return;
WindowCompat.enableEdgeToEdge(act.getWindow());
ViewCompat.setOnApplyWindowInsetsListener(view, (v, insets) -> {
Insets bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
| WindowInsetsCompat.Type.displayCutout()
);
v.setPadding(bars.left, bars.top, bars.right, bars.bottom);
return WindowInsetsCompat.CONSUMED;
});
WindowCompat.setDecorFitsSystemWindows(act.getWindow(), false);
WindowInsetsControllerCompat controller =
WindowCompat.getInsetsController(act.getWindow(), act.getWindow().getDecorView());
if (controller != null) {
// 關鍵:將導航欄圖標顏色設為深色(淺色背景上可見)
// 這會強制系統移除半透明的黑色保護層 (Scrim)
controller.setAppearanceLightNavigationBars(true);
}
}
當然還有一些內嵌重疊問題,如手勢內嵌,因為我的程式沒有這樣設計,無法測試,請以官方文件建議修改。
2025/11/22
我換 pixel 10 了,原本紅米 K60 刷 lineageos
使用 WindowCompat.enableEdgeToEdge 需要用到 androidx.core
implementation 'androidx.core:core:1.17.0'
#或
implementation 'androidx.core:core-ktx:1.17.0'
以上變更後,java 版本也需要修改,尤其我使用 java、kotlin 程式混合要改到 22,至於 gradle 使用 8.9.2
android{
...
compileOptions {
targetCompatibility = 21
sourceCompatibility = 21
}
}另外使用 preference 要符合 target 35 要求避免重疊,找出 preference xml 檔案,加上以下設定:
app:iconSpaceReserved="false"如下圖


搶先發佈留言