Jacky's blog
首页
  • 学习笔记

    • web
    • android
    • iOS
    • vue
  • 分类
  • 标签
  • 归档
收藏
  • tool
  • algo
  • python
  • java
  • server
  • growth
  • frida
  • blog
  • SP
  • more
GitHub (opens new window)

Jack Yang

编程; 随笔
首页
  • 学习笔记

    • web
    • android
    • iOS
    • vue
  • 分类
  • 标签
  • 归档
收藏
  • tool
  • algo
  • python
  • java
  • server
  • growth
  • frida
  • blog
  • SP
  • more
GitHub (opens new window)
  • tutorial
  • jetpack

  • components

  • androidx

  • 动态化
  • apm

  • module

  • harmony

  • tool

  • other

    • Flutter 高频面试问答
    • 生产环境Message分发处理设计
    • Android 事件分发机制
    • android沉浸式设置
    • 调研抖音对harmonyOS4的优化
    • Android 评论at功能的实现
    • 探索抖音禁止录屏
    • 对32位手机崩溃的优化记录
    • GradientDrawable
    • android window
    • color
    • webview白屏检测
    • android Resource
    • deeplink技术
    • android-xml
    • ANDROID IPC
    • BottomSheetBehavior研究与思考
    • viewPager
    • Android密钥系统
    • compiler
    • 提升UI加载速度的几点思考
    • Android零耗时首帧体验
    • jsbridge
    • retrofit动态代理设计
    • gif与属性动画的对比
  • kotlin

  • 《android》
  • other
Jacky
2026-03-17

android沉浸式设置

沉浸式隐藏系统 状态栏/导航栏。 参考官方文档 Hide system bars for immersive mode (opens new window)

val windowInsetsController =
        WindowCompat.getInsetsController(window, window.decorView)
// Configure the behavior of the hidden system bars.
windowInsetsController.systemBarsBehavior =
    WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

// Add a listener to update the behavior of the toggle fullscreen button when
// the system bars are hidden or revealed.
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, windowInsets ->
    // You can hide the caption bar even when the other system bars are visible.
    // To account for this, explicitly check the visibility of navigationBars()
    // and statusBars() rather than checking the visibility of systemBars().
    if (windowInsets.isVisible(WindowInsetsCompat.Type.navigationBars())
        || windowInsets.isVisible(WindowInsetsCompat.Type.statusBars())) {
        binding.toggleFullscreenButton.setOnClickListener {
            // Hide both the status bar and the navigation bar.
            windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
        }
    } else {
        binding.toggleFullscreenButton.setOnClickListener {
            // Show both the status bar and the navigation bar.
            windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
        }
    }
    ViewCompat.onApplyWindowInsets(view, windowInsets)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#android
上次更新: 2026/03/18, 17:50:05
Android 事件分发机制
调研抖音对harmonyOS4的优化

← Android 事件分发机制 调研抖音对harmonyOS4的优化→

最近更新
01
claude
03-18
02
openclaw
03-09
03
产业链整理
01-27
更多文章>
Theme by Vdoing | Copyright © 2019-2026 Jacky | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式