我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@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);
其他回答
创建一个如下所示的主题。
<!-- 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>
如果你使用this.requestWindowFeature(Window.FEATURE_NO_TITLE),当活动通过onCreate启动时,用户仍然可以在启动动画期间看到标题栏。如果你使用@android:style/Theme.Black。NoTitleBar如下所示,标题栏将不会在启动动画期间显示。
<activity
android:name=".MainActivity"
android:label="My App"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:screenOrientation="portrait">
上面的例子显然会覆盖你现有的应用主题,如果你有现有的主题,那么添加<item name="android:windowNoTitle">true</item>到它。
只需使用getActionBar().hide();在你的主活动onCreate()方法中。
在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:theme="@android:style/Theme.Translucent.NoTitleBar"
添加以下行到您的Java文件,
this.requestWindowFeature(Window.FEATURE_NO_TITLE);