我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。

使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。

我可以在某个地方设置无标题样式的项目吗?


当前回答

为你使用的主题添加这两个:

    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>

其他回答

简单地改变你的应用主题的父标签为" theme . appcompat . light . noactionbar "

标题栏可以用两种方式删除,如开发者Android页面所述:

在manifest.xml文件中:

如果你想为应用程序中的所有活动删除它,请在应用程序中添加以下内容: <应用android:主题= " @android:风格/ Theme.Black.NoTitleBar”> 或用于某一特定活动: <活动android:主题= " @android:风格/ Theme.Black.NoTitleBar”>

添加舱单文件,

  android:theme="@android:style/Theme.Translucent.NoTitleBar"

添加以下行到您的Java文件,

  this.requestWindowFeature(Window.FEATURE_NO_TITLE);

我更喜欢:-

AppTheme(整个应用程序主题) AppTheme。NoActionBar(没有操作栏或工具栏的主题) fullscreen(没有动作栏和状态栏的主题)

主题风格喜欢:-

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorDarkPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.NoActionBar.FullScreen" parent="AppTheme.NoActionBar">
    <item name="android:windowFullscreen">true</item>
</style>

在onCreate方法中也把下面的代码放在super.onCreate(savedInstanceState)之后

super.onCreate(savedInstanceState)    
this.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN)

或者如果你想隐藏/显示标题栏在任何点:

private void toggleFullscreen(boolean fullscreen)
{
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    if (fullscreen)
    {
        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    else
    {
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    getWindow().setAttributes(attrs);
}