Upgrade to Pro — share decks privately, control downloads, hide ads and more …

StatusBarをできるだけ簡潔にカスタマイズする

 StatusBarをできるだけ簡潔にカスタマイズする

[Online] potatotips #73 iOS/Android開発Tips共有会のLT資料

https://potatotips.connpass.com/event/202810/
サンプルアプリ: https://github.com/subroh0508/Display-Cutouts-Sample

subroh_0508

March 26, 2021
Tweet

More Decks by subroh_0508

Other Decks in Technology

Transcript

  1. 4UBUVT#BSͷΧελϚΠζ 㾎Ͱ͖Δ͜ͱ  എܠͷ৭Λม͑Δ  ΞΠίϯͷ-JHIU%BSLΛ੾Γ׵͑Δ  4UBUVT#BSͷഎޙ·Ͱίϯςϯπ͕ඳը͞ΕΔΑ͏ʹ͢Δ  4UBUVT#BSͦͷ΋ͷΛඇදࣔʹ͢ΔɹɹɹFUD

    BOESPJETUBUVT#BS$PMPSଐੑ BOESPJEXJOEPX-JHIU4UBUVT#BSଐੑ BOESPJEXJOEPX'VMMTDSFFOଐੑ TFU4ZTUFN6J7JTJCJMJUZϝιου ΍ΕΔ͜ͱଟ͗ͯ͢Α͘Θ͔ΒΜ😇 4%,7FSTJPOͰมΘΔͱ͜Ζ΋ͪΐ͍ͪΐ͍͋Δ😇
  2. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎TFU0O"QQMZ8JOEPX*OTFUTϝιου  8JOEPX*OTFUT γεςϜ6*ͷඳըྖҬ ΛಈతʹऔಘͰ͖Δ val customStatusBar: TextView =

    ... window.decorView.setOnApplyWindowInsetsListener { _, insets -> setCustomStatusBarHeight(customStatusBar, insets) window.decorView.onApplyWindowInsets(insets) }
  3. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎TFU0O"QQMZ8JOEPX*OTFUTϝιου  8JOEPX*OTFUT γεςϜ6*ͷඳըྖҬ ΛಈతʹऔಘͰ͖Δ val customStatusBar: TextView =

    ... window.decorView.setOnApplyWindowInsetsListener { _, insets -> setCustomStatusBarHeight(customStatusBar, insets) window.decorView.onApplyWindowInsets(insets) } γεςϜ6*ͷঢ়ଶ͕มΘΔ౓ʹ8JOEPX*OTFUT͕ྲྀΕͯ͘Δ 8JOEPX*OTFUT͔Β4UBUVT#BSͷߴ͞ΛऔಘͰ͖Δʂ
  4. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎TFU0O"QQMZ8JOEPX*OTFUTϝιου  8JOEPX*OTFUT γεςϜ6*ͷඳըྖҬ ΛಈతʹऔಘͰ͖Δ val customStatusBar: TextView =

    ... window.decorView.setOnApplyWindowInsetsListener { _, insets -> setCustomStatusBarHeight(customStatusBar, insets) window.decorView.onApplyWindowInsets(insets) } Կނ͜ͷϝιουͰ8JOEPX*OTFUTΛऔಘͰ͖Δʜʁ ࠷ޙʹ࣮ߦ͍ͯ͠ΔPO"QQMZ8JOEPXT*OTFUTJTԿऀʜʁ
  5. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎7JFXEJTQBUDI"QQMZ8JOEPX*OTFUT  ਌7JFX͔Β౉͞Εͨ8JOEPX*OTFUTΛద༻͢Δϝιου public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { try

    { mPrivateFlags3 |= PFLAG3_APPLYING_INSETS; if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) { return mListenerInfo.mOnApplyWindowInsetsListener .onApplyWindowInsets(this, insets); } else { return onApplyWindowInsets(insets); } } finally { mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS; } }
  6. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎7JFXEJTQBUDI"QQMZ8JOEPX*OTFUT  ਌7JFX͔Β౉͞Εͨ8JOEPX*OTFUTΛద༻͢Δϝιου public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { try

    { mPrivateFlags3 |= PFLAG3_APPLYING_INSETS; if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) { return mListenerInfo.mOnApplyWindowInsetsListener .onApplyWindowInsets(this, insets); } else { return onApplyWindowInsets(insets); } } finally { mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS; } } TFU0O"QQMZ8JOEPX*OTFUT-JTUFOFSͰ୅ೖͨ͠ -JTUFOFS͕͜͜Ͱݺ͹ΕΔ ˠ8JOEPX*OTFUTͷద༻ॲཧΛ֎෦͔ΒΧελϚΠζͰ͖Δʂ
  7. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎7JFXEJTQBUDI"QQMZ8JOEPX*OTFUT  ਌7JFX͔Β౉͞Εͨ8JOEPX*OTFUTΛద༻͢Δϝιου public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { try

    { mPrivateFlags3 |= PFLAG3_APPLYING_INSETS; if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) { return mListenerInfo.mOnApplyWindowInsetsListener .onApplyWindowInsets(this, insets); } else { return onApplyWindowInsets(insets); } } finally { mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS; } } -JTUFOFS͕ଘࡏ͠ͳ͍৔߹ʹ࣮ߦ͞ΕΔͷ͕PO"QQMZ8JOEPX*OTFUT ˠ%FDPS7JFXຊདྷͷద༻ॲཧ΋ඞཁͳͷͰ -JTUFOFSͷ຤ඌͰPO"QQMZ8JOEPX*OTFUT΋ݺͿ
  8. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎8JOEPX*OTFUT͔Βͷ4UBUVT#BSͷߴ͞औಘ fun setCustomStatusBarHeight(textView: TextView, insets: WindowInsets) { textView.height =

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) insets.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()).top else insets.systemWindowInsetTop }
  9. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎8JOEPX*OTFUT͔Βͷ4UBUVT#BSͷߴ͞औಘ fun setCustomStatusBarHeight(textView: TextView, insets: WindowInsets) { textView.height =

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) insets.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()).top else insets.systemWindowInsetTop } "1*7FSTJPOҎԼ͸HFU4ZTUFN8JOEPX*OTFU5PQϝιουΛ࢖͏
  10. 5FYU7JFXͷߴ͞Λಈతʹมߋ 㾎8JOEPX*OTFUT͔Βͷ4UBUVT#BSͷߴ͞औಘ fun setCustomStatusBarHeight(textView: TextView, insets: WindowInsets) { textView.height =

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) insets.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()).top else insets.systemWindowInsetTop } "1*7FSTJPOҎ্͸HFU*OTFUT*HOPSJOH7JTJCJMJUZϝιουΛ࢖͏ γεςϜ6*ͷදࣔɾඇදࣔͷঢ়ଶ໰ΘͣඳըྖҬΛऔಘ͢Δ ˞HFU*OTFUTϝιουͩͱඇදࣔ࣌ʹۭͷྖҬ͕ฦͬͯ͠·͏
  11. 4UBUVT#BSͷදࣔɾඇදࣔ੾Γସ͑ 㾎TFU4ZTUFN6J7JTJCJMJUZ*OTFUT$POUSPMMFSΛར༻ window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_VISIBLE or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) 4%,

    GPSTIPX window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) 4%, GPSIJEF
  12. 4UBUVT#BSͷදࣔɾඇදࣔ੾Γସ͑ 㾎TFU4ZTUFN6J7JTJCJMJUZ*OTFUT$POUSPMMFSΛར༻ window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_VISIBLE or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) 4%,

    GPSTIPX window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) 4%, GPSIJEF 4:45&.@6*@'-"(@7*4*#-&ˠ4UBUVT#BSΛදࣔ
  13. 4UBUVT#BSͷදࣔɾඇදࣔ੾Γସ͑ 㾎TFU4ZTUFN6J7JTJCJMJUZ*OTFUT$POUSPMMFSΛར༻ window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_VISIBLE or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) 4%,

    GPSTIPX window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) 4%, GPSIJEF 4:45&.@6*@'-"(@'6--4$3&&/ˠ4UBUVT#BSΛඇදࣔ 4:45&.@6*@'-"(@*..&34*7&@45*$,: ˠεϫΠϓͰ൒ಁ໌දࣔ ͠͹Β͘ܦͭͱҾͬࠐΉ
  14. 㾎αϯϓϧΞϓϦͰաෆ଍ͳ࣮͘૷ͨ͠ ͸ͣʜ   TVCSPI%JTQMBZ$VUPVUT4BNQMF 㾎ࢀߟจݙ  શը໘Ϟʔυͷ༗ޮԽc"OESPJEσϕϩούʔc"OESPJE%FWFMPQFST EFWFMPQFSBOESPJEDPNUSBJOJOHTZTUFNVJJNNFSTJWF 

    %SPJE,BJHJ4ZTUFN6*Λίϯτϩʔϧͯ͠ɺը໘Λ࠷େݶʹੜ͔ͨ͠ΞϓϦΛߏங͢Δ TQFBLFSEFDLDPNTBUPTIVOCVJMEBQQTUIBUNBLFUIFCFTUVTFTPGEFWJDFTDSFFOTCZDPOUSPMMJOHTZTUFNVJ ৄ͘͠͸ʜ ͋·Γ৮Βͳ͍4UBUVT#BSɺॱংཱͯͯௐ΂Ε͹͜Θ͘ͳ͍ʂ 6*σβΠϯͷ෯͕޿͕Δ͜ͱؒҧ͍ͳ͠ʂੋඇνϟϨϯδʂ💪 5IBOLZPVGPSMJTUFOJOH ϊονରԠ΋ͯ͠·͢ʜ😇