android - 状态栏和导航栏上的 Google Now 渐变/阴影

标签 android gradient shadow navigationbar android-statusbar

我正在尝试制作与 Google Now 类似的状态栏和导航栏渐变。

图片引用:如下所示的矩形区域

enter image description here

在 Android Marshmallow 上尝试以下选项后,

    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowTranslucentStatus">true</item>

我得到以下行为

图片引用:

enter image description here

谁能建议我如何在这两个上获得渐变?
那是渐变还是阴影?

最佳答案

它是用作 scrim 的渐变.要达到这种效果,您要做的第一件事就是移除状态栏和导航栏的半透明底层。 Another answer详细说明如何在较低平台设备上执行此操作;但在 Android Lollipop 及更高版本上,您只需将两个样式属性设置为透明即可完成此操作:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
</resources>

然后,要添加稀松布,您可以使用可绘制的形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <gradient android:type="linear"
        android:angle="270"
        android:centerY="0.3"
        android:startColor="#66000000"
        android:centerColor="#33000000"
        android:endColor="#00000000"/>

</shape>

然后您可以将其设置为布局中 View 的背景:

<View
    android:layout_width="match_parent"
    android:layout_height="72dp"
    android:background="@drawable/scrim"/>

您还可以设置 android:rotation="180" 属性以对屏幕底部使用相同的渐变。

关于android - 状态栏和导航栏上的 Google Now 渐变/阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40960687/

相关文章:

linux - CentOS 6 和 RHEL 6 上 linux 用户名的真正规则是什么?

c++ - 光线追踪阴影

android - Jetpack Compose TextField InputFilter 仅具有货币正则表达式输入

android-如何获得这样的边框

android - 加速度计的最小值和最大值范围以及传感器数据转换

qt - 如何在图像中设置渐变不透明度?

css - 线性渐变的 URL 不起作用

android - 如何获取文件夹中所有图像文件的名称?

android - Java中的渐变背景颜色

java - 具有分割曲面的 blender 模型上出现奇怪的阴影