Reputation: 656
I want to change the color of status bar to match the toolbar. I have try as many as possible code from other answers, and still not working. This code is working in Android 10, but not in Android 11. The code below provide me with a translucent status bar:
class SettingDialog : AppCompatDialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
}
override fun onResume() {
super.onResume()
dialog?.window?.apply {
setLayout(MATCH_PARENT, MATCH_PARENT)
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) //This flag is deprecated
statusBarColor = ContextCompat.getColor(context, R.color.primary_dark)
val insetController = ViewCompat.getWindowInsetsController(decorView)
insetController?.isAppearanceLightStatusBars = true
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val v = inflater.inflate(R.layout.dialog_setting, container, false)
...
return v
}
}
Upvotes: 0
Views: 629
Reputation: 656
Looks like the problem was on the dim background. I've managed to get it working by removing the dim background.
class SettingDialog : AppCompatDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog?.window?.apply {
...
clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
...
}
}
}
Upvotes: 0