Android 如何获取支持操作栏的 AppCompat.Translucent 类型主题? [英] Android how to get AppCompat.Translucent type theme with support actionbar?

查看:23
本文介绍了Android 如何获取支持操作栏的 AppCompat.Translucent 类型主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将支持操作栏添加到我的一个活动中,我以前一直在此活动中使用 theme.translucent 但为了使支持操作栏工作,我需要继承 Theme.AppCompat,我需要在此活动中保持半透明主题,但不幸的是,默认情况下没有我可以看到的 Theme.AppCompat.translucent,有什么办法可以做到这一点?

I would like to add the support actionbar to one of my activities, I previously had been using the theme.translucent with this activity but in order to make the support actionbar work I needed to inherit the Theme.AppCompat, I need to maintain a translucent theme in this activity but unfortunately there isnt a Theme.AppCompat.translucent that i can see by default, is there any way that this can be done?

推荐答案

您可以创建一组新的样式来使用,这些样式与 themes.xml.

You can create a new set of styles to use which have the same properties as Theme.Translucent from themes.xml.

将以下内容添加到您的 style.xml 文件中:

Add the following to your styles.xml file:

<style name="Theme.AppCompat.Translucent">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>

如果您想从主题继承其他内容,例如对话框样式等,您可以将前缀 Theme.AppCompat 更改为其他内容.例如,像 Theme.AppCompat 这样的名称.Light.Translucent 将具有 Light 主题的属性.

You can change the prefix Theme.AppCompat to something else if you want to inherit other things from the theme such as dialog styles etc. For example, a name like Theme.AppCompat.Light.Translucent would have the properties of the Light theme.

要使用新样式,请将主题属性设置为 @style/Theme.AppCompat.Translucent

To use the new style, set the theme property to @style/Theme.AppCompat.Translucent

<activity
    android:name=".TranslucentActivity"
    android:theme="@style/Theme.AppCompat.Translucent" >
</activity>

这篇关于Android 如何获取支持操作栏的 AppCompat.Translucent 类型主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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