Skip to content

Instantly share code, notes, and snippets.

@BattleShipPark
Created December 15, 2020 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BattleShipPark/274a08c7530a24be45bf7340dd62124c to your computer and use it in GitHub Desktop.
Save BattleShipPark/274a08c7530a24be45bf7340dd62124c to your computer and use it in GitHub Desktop.
다이얼로그일 때 네비게이션바 색깔을 변경
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setWhiteNavigationBar(dialog)
}
return dialog
}
@RequiresApi(api = Build.VERSION_CODES.M)
private fun setWhiteNavigationBar(dialog: Dialog) {
val window: Window? = dialog.window
if (window != null) {
val metrics = DisplayMetrics()
window.windowManager.defaultDisplay.getMetrics(metrics)
val dimDrawable = ColorDrawable(Color.TRANSPARENT)
val navigationBarDrawable = ColorDrawable(Color.WHITE)
val layers = arrayOf(dimDrawable, navigationBarDrawable)
val windowBackground = LayerDrawable(layers)
windowBackground.setLayerInsetTop(1, metrics.heightPixels)
window.setBackgroundDrawable(windowBackground)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment