我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
当前回答
我使用的是支持小部件Toolbar v7。 因此,为了能够删除或隐藏标题,我们需要这样写。
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
//Remove¡ing title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
其他回答
第一个答案是角闪石。 以下是我的解释: 添加:
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这个答案。
在onCreate方法中,使用以下代码段:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
现在我做了以下事情。
我声明了一个样式,继承了我的通用样式的所有内容,然后禁用了标题栏。
<style name="generalnotitle" parent="general">
<item name="android:windowNoTitle">true</item>
</style>
现在我可以将此样式设置为我想要隐藏标题栏的每个活动,覆盖应用程序范围的样式并继承所有其他样式信息,因此在样式代码中没有重复。
要将样式应用到特定的Activity,打开AndroidManifest.xml并将以下属性添加到Activity标签中;
<activity
android:theme="@style/generalnotitle">
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);
这是指活动。