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

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

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


当前回答

将此样式添加到style.xml文件中

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

之后,在你不想看到标题栏的特定活动中引用此样式名称到androidManifest.xml,如下所示。

<activity android:name=".youractivityname"
     android:theme="@style/AppTheme.NoActionBar">
</activity>

其他回答

在onCreate()方法中执行此操作。

//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here); 

这是指活动。

你可以修改AndroidManifest.xml:

<activity android:name=".MainActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

或者使用android:theme="@android:style/ theme . black。NoTitleBar"如果你不需要全屏活动。

注意:如果你之前使用了一个'default'视图,你可能也应该把父类从AppCompatActivity改为Activity。

Add

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

在AppTheme内部(style .xml)

WindowManager。LayoutParams在Android Studio文档说FLAG_FULLSCREEN是“窗口标志:隐藏所有的屏幕装饰(如状态栏),而这个窗口显示。”所以这个标志不会让我的内容充满整个屏幕。

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

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