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

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

问题描述

我想隐藏一些活动的标题栏.问题是我对所有活动都应用了一种样式,因此我不能简单地将主题设置为 @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>

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

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 中隐藏 Activity 的标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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