我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
当前回答
第一个答案是角闪石。 以下是我的解释: 添加:
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这个答案。
其他回答
隐藏标题和动作栏我这样做:
在Manifest的activity标签中:
android:theme="@style/AppTheme.NoActionBar"
在Activity.java setContentView之前:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
也就是说,
//删除标题栏
this.requestWindowFeature (Window.FEATURE_NO_TITLE);
//删除通知栏
this.getWindow () .setFlags (WindowManager.LayoutParams。FLAG_FULLSCREEN WindowManager.LayoutParams.FLAG_FULLSCREEN);
注意:你需要在setContentView之前保留这些行
创建一个如下所示的主题。
<!-- 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>
简单地改变你的应用主题的父标签为" theme . appcompat . light . noactionbar "
在onCreate方法中,使用以下代码段:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
或者如果你想隐藏/显示标题栏在任何点:
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);
}