简体   繁体   English

如何在暗模式下隐藏 Android 标题栏?

[英]How to hide Android title bar in dark mode?

I'm using Theme.MaterialComponents.DayNight.NoActionBar for my activity.我正在为我的活动使用Theme.MaterialComponents.DayNight.NoActionBar My goal is to create an activity with no title bar and make the notification bar background as same as app background colour.我的目标是创建一个没有标题栏的活动,并使通知栏背景与应用背景颜色相同。 Everything works fine under normal condition.在正常情况下一切正常。 But when I enable dark theme from the device settings, the title bar suddenly appears.但是当我从设备设置中启用深色主题时,标题栏突然出现。 How can I get rid of title bar for both dark light theme?如何摆脱暗光主题的标题栏?

By default in the themes folder, there will be a normal one and night version change the parent theme in both to parent="Theme.MaterialComponents.DayNight.NoActionBar" like below默认情况下,在主题文件夹中,会有一个正常的一夜版本,将两者中的父主题更改为parent="Theme.MaterialComponents.DayNight.NoActionBar"如下所示

and the theme in manifest to style name in these two themes(same name) for me here android:theme="@style/Theme.Advice"> in manifest以及清单中的主题在这两个主题中的样式名称(相同名称)对我来说android:theme="@style/Theme.Advice">在清单中

Simply go to the Android Manifest file and change NoActionBar to NoTitleBar https://www.xspdf.com/resolution/20749671.html Simply go to the Android Manifest file and change NoActionBar to NoTitleBar https://www.xspdf.com/resolution/20749671.html

you can do it programmatically as well:您也可以以编程方式执行此操作:

this.requestWindowFeature(Window.FEATURE_NO_TITLE)
this.window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

add this in you oncreate call and before setcontent view.在你的 oncreate 调用和 setcontent 视图之前添加它。

as:作为:

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        this.requestWindowFeature(Window.FEATURE_NO_TITLE)
        this.window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main)
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM