1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Status barを透明にする方法

Posted at

直近の案件でStatus Bar部分にもコンテンツを表示したいという要件が合った際に使用したコードを、自分への備忘録も兼ねて記載します。

実装方法

XMLではなくコードから指定します。

// このコードでStatus Barを非表示にし、レイアウトを全画面に表示する
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

// レイアウトの上部にStatus Barの高さの分Paddingを入れることで、Status Barの領域を再確保
findViewById<View>(R.id.root).setPadding(0, getStatusBarHeight(), 0, 0)

// Status Barの部分を透明に塗りつぶす
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = Color.TRANSPARENT

// Status Barに表示されるアイコンが見えるよう調節する
var systemUiVisibility = window.decorView.systemUiVisibilitysystemUiVisibility = systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
window.decorView.systemUiVisibility = systemUiVisibility
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?