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

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

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


当前回答

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

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);
}

其他回答

如果你替换了DarkActionBar的定义,你只需要改变style .xml中的AppTheme样式

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

对NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

在androidmanifest .xml中定义的AppTheme

Add

<item name=“android:windowNoTitle”>true</item>

在AppTheme内部(style .xml)

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

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);
}

第一个答案是角闪石。 以下是我的解释: 添加:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

在oncreate()方法中。

之前:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);

(不仅仅是在setContentView之前) 如果不这样做,你将被强制关闭。 +1这个答案。

咳咳,您可以将主题应用于XML中的单个活动,例如没有标题。换句话说,将其从应用程序标记中取出,打开标记声明并将其放入所需的活动标记中。