Android:AppBarLayout渐变背景

标签 android background android-5.0-lollipop gradient transparent

我尝试实现一个带有渐变背景(从黑色到透明)的工具栏。工具栏位于 AppBarLayout 内,而 AppBarLayout 位于 CoordinatorLayour 内,因为我希望工具栏在滚动屏幕时滑出屏幕(提高 scroll|enterAlways 滚动标志)。这对于 Lollipop 之前的版本非常有效,看起来像这样:

enter image description here

但在 Lollipop 上显示的是:

weird upside down trapezoid in the background

我尝试了工具栏和 appbarlayout 上的其他背景组合,以使工具栏具有渐变背景,但一切都会产生相同的结果。我尝试搜索类似的问题,但没有找到。

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

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gradient">

        <android.support.v7.widget.Toolbar
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:background="@android:color/transparent"
            app:layout_scrollFlags="scroll|enterAlways">

            ...

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

最佳答案

AppBarLayout 强制提升。由于工具栏在 AppBarLayout 内部,并且工具栏是透明的,所以 AppBarLayout 的侧面和底部阴影变得明显。

在您的 AppBarLayout 中包含 app:elevation="0dp"。希望对您有所帮助。

关于Android:AppBarLayout渐变背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31006609/

相关文章:

android - 这个谷歌地图滚动动画叫什么,我如何复制它?

Android Gradient 以编程方式绘制

android - 来自 ListView/row 的 TextView 上的动态背景图像

android - 如何在android Lollipop 版本中以彩色显示通知图标

CheckedTextView 的 Android checkMarkGravity 属性(api 21)

android - 在 state_selected 中单击时,ImageButton 选择器不会触发 state_pressed

android - getGsmSignalStrength() 返回超出范围的值?

java - Android 开始日历 Intent 与开始和结束时间

android - 后台发送数据到邮箱

android - Lollipop 商店中的抽屉指示器