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

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

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


当前回答

对我有用的方法:

1-在styles.xml中:

 <style name="generalnotitle" parent="Theme.AppCompat.Light" >
          <item name="android:windowNoTitle">true</item>   <!-- //this -->     
   </style>

2-在MainActivity中

@Override
protected void onCreate(Bundle savedInstanceState) {          
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); //<< this
    setContentView(R.layout.activity_main);
}

在显式中继承样式: <活动android: name = "。MainActivity @style / generalnotitle“android:主题= >

其他回答

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

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

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

添加舱单文件,

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

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

  this.requestWindowFeature(Window.FEATURE_NO_TITLE);

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

添加主题@style/ theme . appcompat . light。在AndroidManifest.xml中的NoActionBar

<activity
        android:name=".activities.MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    </activity>