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

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

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


当前回答

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

其他回答

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

这是指活动。

在我的例子中,我的活动是扩展AppCompatActivity。

class MyActivity: AppCompatActivity(){
    ...
}

所以,其他答案都不管用。 我必须这样做:

class MyActivity: AppCompatActivity(){
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
}

它确实有效!

如果你的活动扩展了AppCompatActivity,只要在requestWindowFeature(…)之前添加“support”即可。

创建一个如下所示的主题。

 <!-- Variation on the Light theme that turns off the title -->
<style name="MyTheme" parent="android:style/Theme.Black">
    <item name="android:windowNoTitle">true</item>
</style>

只需使用getActionBar().hide();在你的主活动onCreate()方法中。

在onCreate方法中,使用以下代码段:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);