为什么我们不能使用带有和 ActionBar 的 Translucent 系统栏 [英] Why can't we use a Translucent system bars with and ActionBar

查看:25
本文介绍了为什么我们不能使用带有和 ActionBar 的 Translucent 系统栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将我的应用更新到 Kitkat 时,我只是想使用 Translucent 属性让它们在 KitKat 上看起来更漂亮:

While updating my apps to Kitkat, I just wanted to give them a gorgeous look on KitKat using the Translucent property:

半透明的系统栏

您现在可以使用新主题 Theme.Holo.NoActionBar.TranslucentDecor 和 Theme.Holo.Light.NoActionBar.TranslucentDecor 使系统栏部分半透明.通过启用半透明系统栏,您的布局将填充系统栏后面的区域,因此您还必须为布局中不应被系统栏覆盖的部分启用 [fitsSystemWindows][4].

You can now make the system bars partially translucent with new themes, Theme.Holo.NoActionBar.TranslucentDecor and Theme.Holo.Light.NoActionBar.TranslucentDecor. By enabling translucent system bars, your layout will fill the area behind the system bars, so you must also enable [fitsSystemWindows][4] for the portion of your layout that should not be covered by the system bars.

我唯一担心的是我想使用听起来与 Google 想要的相反的 ActionBar(两个主题都有 NoActionBar:

My only concern is that I would like to use an ActionBar which sounds the opposite of what Google wants (both theme have NoActionBar:

Theme.Holo.NoActionBar.TranslucentDecor 
Theme.Holo.Light.NoActionBar.TranslucentDecor 

由于我不打算使用一些技巧或技巧来让它发挥作用,我只是想知道是否有一些正确的方法可以实现这一目标,或者这是否会违反 Google 指南.

As I don't plan to use some hacks or tricks to make it work, I just wanted to know if there was some correct way to achieve this or if this would be against Google guidelines.

推荐答案

您可以创建自己的主题,将 android.R.attr#windowTranslucentStatus 设置为 true 来实现不丢失ActionBar的相同效果.

You can create your own theme with android.R.attr#windowTranslucentStatus set to true to achieve the same effect without losing the ActionBar.

来自文档:

指示此窗口是否请求半透明状态栏的标志.对应到 {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS}.

Flag indicating whether this window requests a translucent status bar. Corresponds to {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS}.

样式 - 请记住,这些将放在 values-v19 中.

Styles - Remember, these would go in values-v19.

<style name="TranslucentStatusBar" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/TranslucentActionBar</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

<style name="TranslucentActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@android:color/transparent</item>
</style>

布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_blue_dark"
    android:fitsSystemWindows="true" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_purple" />

</FrameLayout>

结果

这篇关于为什么我们不能使用带有和 ActionBar 的 Translucent 系统栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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