状态栏&上的Google即时渐变/阴影导航栏 [英] Google Now gradient/shadow on status bar & navigation bar
问题描述
我正在尝试使状态栏和导航栏的渐变与Google即时相似。
I'm trying to make a similar status bar and navigation bar gradient as Google Now.
图片参考:矩形区域如下所示
Image Reference: Rectangular area indicated as below
在Android棉花糖上尝试以下选项后,
After trying the below option on Android Marshmallow,
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
我得到以下行为
图片参考:
有人可以建议我如何在这两个位置上获得渐变吗?
是渐变还是阴影?
Can anyone suggest me how to get gradient on both these ?
Is that a gradient or is that a shadow ?
推荐答案
它是用作渐变的稀松布。要实现此效果,您要做的第一件事就是删除状态栏和导航栏的半透明底衬。 另一个答案详细说明了如何在较低平台的设备上执行此操作;但是在Android Lollipop及更高版本上,只需将两个样式属性设置为透明即可做到这一点:
It is a gradient being used as a scrim. To achieve this effect, the first thing you have to do is remove the semi-transparent underlay for the Status and Navigation bars. Another answer details how you can do this on lower platform devices; but on Android Lollipop and higher, you can do this simply by setting two style attributes to transparent:
<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>
然后,要添加稀松布,可以使用可绘制形状:
Then, to add the scrim, you can use a shape drawable:
<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>
然后,您可以将其设置为视图的背景
在您的布局中:
Then you can just set this as the background to a View
in your layout:
<View
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="@drawable/scrim"/>
您还可以设置 android:rotation = 180
属性可在屏幕底部使用相同的渐变。
You can also set the android:rotation="180"
attribute to use the same gradient for the bottom of the screen.
这篇关于状态栏&上的Google即时渐变/阴影导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!