1、去掉actionbar
2、添加style文件
<style name="Theme.FavDish.NoActionBar" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
2、
在mainfest中应用该style
android:theme="@style/Theme.FavDish.NoActionBar"
3、统一控制显示和隐藏actionbar
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
window.insetsController?.hide(WindowInsets.Type.statusBars())
}else{
@Suppress("DEPRECATION")
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
4、运行结果: