当前位置: 首页 > 知识库问答 >
问题:

在Android Kitkat 4.4版本中,使用状态栏下的导航抽屉时,状态栏颜色显示为白色,不透明

彭宏阔
2023-03-14

我使用的是material design navigation drawer,我想在android kitkat 4.4版本中的透明状态栏下进行抽屉布局,因为我使用了fitsystemwindow true,但当使用fitsystemwindow true时,它会显示白色状态栏,我也使用了android:WindowTransparcentStatus true和android:WindowTransparcentNavigation false以我的风格。values-v19下的xml,但它仍然在android kitkat 4.4中显示白色状态栏。在lolipop中很容易实现我知道的状态栏,所以如何在android kitkat 4.4中使状态栏透明,我在谷歌上搜索了很多,但没有解决方案。请帮我解决这个问题。提前谢谢。

V19/style.xml

 <resources xmlns:android="http://schemas.android.com/tools">

        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="android:windowTranslucentStatus">true</item>
            <item name="android:windowTranslucentNavigation">false</item>


        </style>

    </resources>

主要活动。xml

 <?xml version="1.0" encoding="utf-8"?>

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

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:paddingTop="5dp"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tablayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark"
                app:tabGravity="fill"
                app:tabIndicatorColor="#f8f880"
                app:tabSelectedTextColor="#ff8800"
                app:tabTextColor="#ffffff" />

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_done" />

    </android.support.design.widget.CoordinatorLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ffffff"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>

共有1个答案

谭成业
2023-03-14

适用于API 21

<style name="AppTheme" parent="android:Theme.Holo.NoActionBar.TranslucentDecor">
    ...
</style>

对于API级别19

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowTranslucentStatus">true</item>
</style>

此外,您的布局应该有android:fitsystemwindows=“false”

注意:在Android KitKat中,除非使用以下解决方案,否则无法更改状态栏的颜色,因为只有在Lollipop中,谷歌才引入了statuBarColor属性

因此,你需要检查这个透明状态栏在KITKAT

 类似资料:
  • 但是像App Store里一样透明模糊但是有背景色,问题是导航控制器的背景色不像正常的那样在状态栏下。 我的代码: 编辑:我有一个自定义类和视图控制器嵌入在一个 Swift 3,Xcode 8.0 beta 5。

  • 我现在有一个视图控制器。我希望状态栏的颜色与导航栏的颜色匹配。 我已将UIViewControllerBasedStatusBarAppearance设置为“是”,因为我不希望在整个应用程序中进行此更改。 我在设定自我。导航控制器。导航栏。但这只是改变了导航栏的颜色。状态栏保持较浅的颜色。 我已经尝试过setNeedsStatusBarAppearanceUpdate和preferredStatu

  • 因此,我在这里读了几篇关于更改状态栏文本颜色的帖子,但都没用。所以我最初的问题是,状态栏现在在iOS7中是透明的,我希望它是带黑色文本的白色。所以我把它添加到我的viewcontroller中。 好的,现在状态是黑对黑,不能阅读文本,但至少它不是透明的。所以现在我做了下面的事情。 进入plist并添加了这个 然后我将此添加到我的应用程序委托 现在我有一个状态栏是白色的,但是文本是白色的,所以你看不

  • 我有一个带有。我们的客户要求我们根据从中选择的项目,动态更改此活动的操作栏颜色和相应的状态栏颜色。这很容易做到。然而,我的问题是,当我动态更改状态栏颜色时,我无法保持状态栏透明。当我打开抽屉时,彩色状态栏会覆盖抽屉布局的顶部,如下所示: 但是,我希望我的看起来像这样: 这我可以用下面的行做: 然而,我的问题不是我不能设置状态栏的透明度。我的问题是,状态栏和操作栏颜色的动态更改不适用于。我的状态栏颜

  • 如果你认为它重复了一些其他的问题,那么我应该让你现在我已经尝试了3,4页的谷歌搜索,也实现了他们。

  • 出于某种原因,状态栏现在是白色的。或者更确切地说,是灰白色,在明亮的背景下隐约可见图标的另一种白色阴影。这是错误的,因为我的应用栏布局使用蓝色阴影作为其颜色。到目前为止,这一直工作正常,我不知道我做了什么导致这种情况。我尝试手动将状态BarColor设置为colorPrimaryDark (#0277bd),但它不起作用。 我只是不知道为什么会发生这种情况。我正在粘贴我的活动的布局.xml,也许有