我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
当前回答
为你使用的主题添加这两个:
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
其他回答
这解决了我的问题
在表现我的活动:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
在“AppTheme”名称下的样式:
<resources>
<!-- Base application theme. -->
<style name="AppTheme"
parent="Theme.AppCompat.Light.NoActionBar">
**<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>**
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
在onCreate方法中,使用以下代码段:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
隐藏标题和动作栏我这样做:
在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之前保留这些行
现在我做了以下事情。
我声明了一个样式,继承了我的通用样式的所有内容,然后禁用了标题栏。
<style name="generalnotitle" parent="general">
<item name="android:windowNoTitle">true</item>
</style>
现在我可以将此样式设置为我想要隐藏标题栏的每个活动,覆盖应用程序范围的样式并继承所有其他样式信息,因此在样式代码中没有重复。
要将样式应用到特定的Activity,打开AndroidManifest.xml并将以下属性添加到Activity标签中;
<activity
android:theme="@style/generalnotitle">
如果你替换了DarkActionBar的定义,你只需要改变style .xml中的AppTheme样式
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
对NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
在androidmanifest .xml中定义的AppTheme