【问题标题】:Android Navigation Bar and Status Bar transparency with insets带有插图的 Android 导航栏和状态栏透明度
【发布时间】:2021-10-10 02:21:24
【问题描述】:

在尝试为 Android 实现透明导航和状态栏(边缘到边缘)时,我关注了 this guide。我正在使用自定义顶栏,以便在滚动时将其隐藏。

    <com.google.android.material.appbar.AppBarLayout
        app:liftOnScroll="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/topAppBar"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:title="Calorie Vault"
            style="@style/Widget.MaterialComponents.Toolbar.Primary"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize" />

    </com.google.android.material.appbar.AppBarLayout>

我将WindowCompat.setDecorFitsSystemWindows(window, false) 添加到我的 MainActivity。 然后,在我的 Fragment 中,我使用 insets 将 UI 向上推,这样 3 按钮导航就不会覆盖一些可点击的界面。

        ViewCompat.setOnApplyWindowInsetsListener(view) { view, windowInsets ->
            val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())

            view.updatePadding(
                top = insets.top, // this is for the tool bar inset
                bottom = insets.bottom // lift up the bottom part of the UI above navigation bar
            )
            WindowInsetsCompat.CONSUMED
        }

我的主题是这样的:

    <style name="Theme.Calorie_vault" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/white</item>
        <item name="colorPrimaryVariant">@color/light_teal</item>
        <item name="colorOnPrimary">@color/black</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/light_teal</item>
        <item name="colorSecondaryVariant">@color/light_teal</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">@android:color/transparent</item>
        <item name="android:enforceStatusBarContrast">false</item>
        <!-- Customize your theme here. -->
        <item name="android:enforceNavigationBarContrast">false</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:windowLightStatusBar">true</item>
    </style>

但是我添加的那些插图不是透明的。这是它们的外观图片:screen shot. 注意手势导航栏的颜色不同。

如何去除插图的颜色?

【问题讨论】:

    标签: android kotlin android-layout material-design


    【解决方案1】:

    将视图的背景设置为透明。

    【讨论】:

      猜你喜欢
      • 2016-10-27
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 2017-08-28
      • 1970-01-01
      相关资源
      最近更新 更多