我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
当前回答
标题栏可以用两种方式删除,如开发者Android页面所述:
在manifest.xml文件中:
如果你想为应用程序中的所有活动删除它,请在应用程序中添加以下内容: <应用android:主题= " @android:风格/ Theme.Black.NoTitleBar”> 或用于某一特定活动: <活动android:主题= " @android:风格/ Theme.Black.NoTitleBar”>
其他回答
你可以修改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。
简单地改变你的应用主题的父标签为" theme . appcompat . light . noactionbar "
将此样式添加到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方法中,使用以下代码段:
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);
}