I'm using the BottomSheetDialogFragment
and I'm overriding this to add my theme :
override fun getTheme() = R.style.BottomSheetDialogTheme
Where this style looks like :
<style name="BottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/btmsheetStyle</item>
<item name="android:navigationBarColor">@color/white</item>
</style>
<style name="btmsheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:backbround">@drawable/rounded_dialog</item>
</style>
My idea is to have the BottomSheetDialogFragment
as the right image but is showing as the left one
I ended up doing a hack to make it work but the problem is that I'm using a deprecated method and perhaps in Android R
it crashes, so I would like to make it better.
This is how I ended up doing the white nav bar android
@RequiresApi(api = Build.VERSION_CODES.M)
private fun setWhiteNavigationBar(dialog: Dialog) {
val window = dialog.window
window?.let {
val displayMetrics = DisplayMetrics()
it.windowManager.defaultDisplay.getMetrics(displayMetrics) <-- deprecated
val navigationBarDrawable = GradientDrawable()
navigationBarDrawable.shape = GradientDrawable.RECTANGLE
navigationBarDrawable.setColor(Color.WHITE)
val layers = arrayOf(navigationBarDrawable)
val windowBackground = LayerDrawable(layer)
windowBackground.setLayerInsetTop(1, displayMetrics.heightPixels)
it.setBackgroundDrawable(windowBackground)
}
}
override fun onCreateDialog(savedInstanceState: Bunde?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setWhiteNavigationBar(dialog)
}
return dialog
}
It does work, but I don't like the deprecated stuff, is there any way to make it better? With style, and avoid having overriding creating dialogs etc?