jjzjj

针对 API 28 (Android 9) 时,Android 半透明状态栏始终为灰色且适用于 fitsSystemWindows

coder 2023-12-13 原文

从API 21开始,当样式包含<item name="android:windowTranslucentStatus">true</item>时布局包括android:fitsSystemWindows="true"状态栏变为半透明,抽屉布局(如抽屉导航)在状态栏后面滑动。在针对 API 28 之前,状态栏的基色将由 colorPrimaryDark 设置或 android:statusBarColor .现在这些值被忽略了。

这个问题实际上出现在com.android.support:design:27.1.0 , 但当时我认为这是一个错误并继续使用 com.android.support:design:27.0.2 .随着 API 28 的延续,这似乎是一个未记录的设计更改。那么,使用fitsSystemWindows时如何设置状态栏背景色呢? API >= 28?

最佳答案

事实证明,这个问题的答案是状态栏的基本颜色现在由设置为 fitsSystemWindows 的布局项的背景设置。然后半透明的状态栏稀松布使该颜色变暗。因此,在我的例子中,fitsSystemWindows 是在 DrawerLayout 内的 CoordinatorLayout 上指定的。在 CoordinatorLayout 上设置 android:background 允许控制基本状态栏颜色。

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent" >

    <!-- `android:fitsSystemWindows="true"` moves `root_coordinatorlayout` below the system status bar.
     When it is specified, the theme should include `<item name="android:windowTranslucentStatus">true</item>`.
     `android:background` sets the background color of the status bar, which is then overlaid with a scrim. -->
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/root_coordinatorlayout"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="com.my.acivity"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:background="#FF64DD17" >

        <!-- The purpose of the `LinearLayout` is to place the included `main_webview` below `app_bar_layout`. -->
        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:orientation="vertical" >

            <!-- The `AppBarLayout` theme has to be defined here because the activity uses a `NoActionBar` theme. -->
            <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar_layout"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:theme="@style/AppBarLight" >

                <android.support.v7.widget.Toolbar
                    android:id="@+id/app_bar"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent" />
            </android.support.design.widget.AppBarLayout>

            <!-- Include the main views. -->
            <include layout="@layout/main_views" />
        </LinearLayout>
    </android.support.design.widget.CoordinatorLayout>

    <!-- The left drawer. -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigationview"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header"
        app:menu="@menu/webview_navigation_menu"
        app:itemIconTint="?attr/navigationIconTintColor" />

    <!-- Include the right drawer. -->
    <include layout="@layout/right_drawer" />

稀松布采用 #FF64DD17 并将其变暗为 #FF3C850E

当抽屉打开时,额外的稀松布覆盖了抽屉后面的整个应用程序,使状态栏变暗到 #FF183405

关于针对 API 28 (Android 9) 时,Android 半透明状态栏始终为灰色且适用于 fitsSystemWindows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51884221/

有关针对 API 28 (Android 9) 时,Android 半透明状态栏始终为灰色且适用于 fitsSystemWindows的更多相关文章

  1. ruby-on-rails - ActionController::RoutingError: 未初始化常量 Api::V1::ApiController - 2

    我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc

  2. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  3. ruby-on-rails - Mandrill API 模板 - 2

    我正在使用Mandrill的RubyAPIGem并使用以下简单的测试模板:testastic按照Heroku指南中的示例,我有以下Ruby代码:require'mandrill'm=Mandrill::API.newrendered=m.templates.render'test-template',[{:header=>'someheadertext',:main_section=>'Themaincontentblock',:footer=>'asdf'}]mail(:to=>"JaysonLane",:subject=>"TestEmail")do|format|format.h

  4. ruby-on-rails - 在 Ruby (on Rails) 中使用 imgur API 获取图像 - 2

    我正在尝试使用Ruby2.0.0和Rails4.0.0提供的API从imgur中提取图像。我已尝试按照Ruby2.0.0文档中列出的各种方式构建http请求,但均无济于事。代码如下:require'net/http'require'net/https'defimgurheaders={"Authorization"=>"Client-ID"+my_client_id}path="/3/gallery/image/#{img_id}.json"uri=URI("https://api.imgur.com"+path)request,data=Net::HTTP::Get.new(path

  5. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  6. ruby-on-rails - 使用 HTTParty 的非常基本的 Rails 4.1 API 调用 - 2

    Rails相对较新。我正在尝试调用一个API,它应该向我返回一个唯一的URL。我的应用程序中捆绑了HTTParty。我已经创建了一个UniqueNumberController,并且我已经阅读了几个HTTParty指南,直到我想要什么,但也许我只是有点迷路,真的不知道该怎么做。基本上,我需要做的就是调用API,获取它返回的URL,然后将该URL插入到用户的数据库中。谁能给我指出正确的方向或与我分享一些代码? 最佳答案 假设API为JSON格式并返回如下数据:{"url":"http://example.com/unique-url"

  7. ruby-on-rails - 是否使用 API - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我的公司有一个巨大的数据库,该数据库接收来自多个来源的(许多)事件,用于监控和报告目的。到目前为止,数据中的每个新仪表板或图形都是一个新的Rails应用程序,在巨大的数据库中有额外的表,并且可以完全访问数据库内容。最近,有一个想法让外部(不是我们公司,而是姊妹公司)客户访问我们的数据,并且决定我们应该公开一个只读的RESTfulAPI来查询我们的数据。我的观点是-我们是否也应该为我们的自己

  8. ruby - Ruby 中的必应搜索 API - 2

    我读了"BingSearchAPI-QuickStart"但我不知道如何在Ruby中发出这个http请求(Weary)如何在Ruby中翻译“Stream_context_create()”?这是什么意思?"BingSearchAPI-QuickStart"我想使用RubySDK,但我发现那些已被弃用前(Rbing)https://github.com/mikedemers/rbing您知道Bing搜索API的最新包装器(仅限Web的结果)吗? 最佳答案 好吧,经过一个小时的挫折,我想出了一个办法来做到这一点。这段代码很糟糕,因为它是

  9. python - 用于 Python 或 Ruby 的 Amazon Book API? - 2

    这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:AmazonAPIlibraryforPython?我正在寻找一个AmazonAPI,它可以让我:按书名或作者查找书籍显示书籍封面获取有关每本书的信息(价格、评级、评论数、格式、页数等)Python或Ruby库都可以(我只想要最容易使用的库)。有什么建议么?我知道在SO上还有其他一些关于此的帖子,但这些API似乎很快就过时了。[几个月前我尝试了几个建议的Ruby库,但无法让它们中的任何一个工作。]

  10. ruby - Google-api-ruby-client 翻译 API 示例 - 2

    很高兴看到google代码:google-api-ruby-client项目,因为这对我来说意味着Ruby人员可以使用GoogleAPI-s来完善代码。虽然我现在很困惑,因为给出的唯一示例使用Buzz,并且根据我的实验,Google翻译(v2)api的行为必须与google-api-ruby-client中的Buzz完全不同。.我对“Explorer”演示示例很感兴趣——但据我所知,它并不是一个探索器。它所做的只是调用一个Buzz服务,然后浏览它已经知道的关于Buzz服务的事情。对我来说,Explorer应该让您“发现”所公开的服务和方法/功能,而不一定已经知道它们。我很想听听使用这个

随机推荐