Slide 1

Slide 1 text

Android 15 でアクション バー表示時にステータスバー が白くなってしまう問題 potatotips #89

Slide 2

Slide 2 text

@tonionagauzzi potatotips #89 2

Slide 3

Slide 3 text

https://blog.cybozu.io/entry/2024/10/21/080000 以下のブログの内容を発表します! potatotips #89 3

Slide 4

Slide 4 text

Android 14 potatotips #89 4

Slide 5

Slide 5 text

targetSdk 34 → 35 potatotips #89 5

Slide 6

Slide 6 text

Android 15 potatotips #89 6

Slide 7

Slide 7 text

レイアウトを調整 override fun onCreate(savedInstanceState: Bundle?) { ... // View をステータスバーの高さぶん下へずらす ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.root_view)) { view, windowInsets -> val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) view.setPadding(insets.left, insets.top, insets.right, insets.bottom) WindowInsetsCompat.CONSUMED } // Android 14以下でもEdge-to-edgeにする(任意) enableEdgeToEdge( statusBarStyle = SystemBarStyle.dark(Color.TRANSPARENT), navigationBarStyle = SystemBarStyle.dark(Color.TRANSPARENT) ) } potatotips #89 7

Slide 8

Slide 8 text

Android 15 potatotips #89 8

Slide 9

Slide 9 text

しかし… potatotips #89 9

Slide 10

Slide 10 text

いくつかの画面は ステータスバーが白い… potatotips #89 10

Slide 11

Slide 11 text

背景色を設定してみた potatotips #89 11

Slide 12

Slide 12 text

白いまま… なぜ? potatotips #89 12

Slide 13

Slide 13 text

レイアウト構成を確認 potatotips #89 13

Slide 14

Slide 14 text

謎の 56dp potatotips #89 14

Slide 15

Slide 15 text

ここが アプリ外領域に なっている… potatotips #89 15

Slide 16

Slide 16 text

アクションバーを消すと potatotips #89 16

Slide 17

Slide 17 text

0dpになった potatotips #89 17

Slide 18

Slide 18 text

どうやら、アクションバーの 問題らしい potatotips #89 18

Slide 19

Slide 19 text

最初に思いついた対策 potatotips #89 19

Slide 20

Slide 20 text

ステータスバーに背景色を付ける ここを黒く塗る potatotips #89 20

Slide 21

Slide 21 text

setStatusBarColor deprecated... 適切な背景を使いなさいと言われた potatotips #89 21

Slide 22

Slide 22 text

Edge-to-edgeは、ウィンドウ全域を 活用してコンテンツを表示するもの potatotips #89 22

Slide 23

Slide 23 text

ステータスバーに色を塗るよりも レイアウトを変えたほうがよい potatotips #89 23

Slide 24

Slide 24 text

でも古いレイアウトほど 書き換えコストは高い… potatotips #89 24

Slide 25

Slide 25 text

本題:アクションバー利用者は どうすればよいか potatotips #89 25

Slide 26

Slide 26 text

以下の2通り 1. Edge-to-edge を無効化する 2. アクションバーを消す potatotips #89 26

Slide 27

Slide 27 text

1. Edge-to-edge を無効化する <item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item> ... potatotips #89 27

Slide 28

Slide 28 text

これまでの見た目を維持! この方式は将来廃止される https://developer.android.com/reference/android/R.attr#windowOptOutEdge ToEdgeEnforcement potatotips #89 28

Slide 29

Slide 29 text

2. アクションバーを消す 方法はいくつかある o ツールバーに置き換える(XML) o TopAppBarに置き換える(Compose) o アプリバーを自作する o アプリバーを使わない見た目にする 対応例はブログにて紹介 https://blog.cybozu.io/entry/2024/10/21/080000#2- %E3%82%A2%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%90%E3%83%BC%E3% 82%92%E6%B6%88%E3%81%99 potatotips #89 29

Slide 30

Slide 30 text

まとめ potatotips #89 30

Slide 31

Slide 31 text

• targetSdk=35でアクションバー使うと、 ステータスバーの背景を設定できない • Edge-to-edge を無効化するのは一時しの ぎ • アクションバーではない方法でアプリバー を表示するか、レイアウトを変えよう! potatotips #89 31

Slide 32

Slide 32 text

一緒に働くメンバーを募集中です! https://cybozu.co.jp/recruit/entry/career/android-engineer.html 興味ある方は、カジュアル面談可能です! potatotips #89 32

Slide 33

Slide 33 text

ありがとうございました! potatotips #89 33