如何使用现有的自定义主题隐藏 XML 中活动的标题栏 [英] How to hide the title bar for an Activity in XML with existing custom theme

查看:28
本文介绍了如何使用现有的自定义主题隐藏 XML 中活动的标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏我的一些活动的标题栏.问题是我对所有活动应用了样式,因此我不能简单地将主题设置为 @android:style/Theme.NoTitleBar.

I want to hide the titlebar for some of my activities. The problem is that I applied a style to all my activities, therefore I can't simply set the theme to @android:style/Theme.NoTitleBar.

使用 NoTitleBar 主题作为我样式的父主题会从我的所有活动中删除标题栏.

Using the NoTitleBar theme as a parent for my style would remove the title bar from all of my activities.

我可以在某处设置无标题样式项吗?

Can I set a no title style item somewhere?

推荐答案

我现在做了以下事情.

我声明了一个样式,它继承了我的一般样式的所有内容,然后禁用了 titleBar.

I declared a style inheriting everything from my general style and then disabling the titleBar.

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>

现在我可以将此样式设置为每个我想要隐藏标题栏的活动,覆盖应用程序范围的样式并继承所有其他样式信息,因此样式代码中没有重复.

Now I can set this style to every Activity in which I want to hide the title bar overwriting the application wide style and inheriting all the other style informations, therefor no duplication in the style code.

要将样式应用到特定 Activity,请打开 AndroidManifest.xml 并将以下属性添加到 activity 标记;

To apply the style to a particular Activity, open AndroidManifest.xml and add the following attribute to the activity tag;

<activity
    android:theme="@style/generalnotitle">

这篇关于如何使用现有的自定义主题隐藏 XML 中活动的标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆