我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@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这个答案。
其他回答
将此样式添加到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);
这是指活动。
标题栏可以用两种方式删除,如开发者Android页面所述:
在manifest.xml文件中:
如果你想为应用程序中的所有活动删除它,请在应用程序中添加以下内容: <应用android:主题= " @android:风格/ Theme.Black.NoTitleBar”> 或用于某一特定活动: <活动android:主题= " @android:风格/ Theme.Black.NoTitleBar”>
添加主题@style/ theme . appcompat . light。在AndroidManifest.xml中的NoActionBar
<activity
android:name=".activities.MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>
添加舱单文件,
android:theme="@android:style/Theme.Translucent.NoTitleBar"
添加以下行到您的Java文件,
this.requestWindowFeature(Window.FEATURE_NO_TITLE);