Google即时状态栏和导航栏上的渐变/阴影
我正在尝试使Google状态栏和导航栏渐变的状态类似。Google即时状态栏和导航栏上的渐变/阴影
图像参考:矩形区域表示如下
试图在Android棉花糖下面的选项后,
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
我得到以下行为
图像参考:
任何人都可以建议我如何得到这两个渐变?
这是一个渐变或是一个影子?
这是一个梯度被用作scrim。要实现这种效果,首先必须删除状态栏和导航栏的半透明底层。 Another answer详细说明如何在较低的平台设备上执行此操作;但在Android棒棒糖或更高版本,你可以简单地通过设置两个样式做这个属性透明:
<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"
属性使用相同的梯度个底部e屏幕。
如果我注意到它正确,我可以看到,它不是谷歌现在的应用程序,有纱布,但主屏幕(即状态栏本身有稀松布)。我们可以检查状态栏的android源代码,如何应用该稀松布。 –
@Jitendar我不认为它直接应用到状态栏(尽管我不会完全排除它)。我认为[Google即时桌面](https://play.google.com/store/apps/details?id=com.google.android。launcher&hl = en),它不是开源的,它将内容稀松布应用到主屏幕。 – Bryan
首先添加样式,使完全透明的操作状态栏:
<!-- Base application theme. -->
<style name="TransparentTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
<item name="android:windowBackground">@null</item>
<item name="android:actionBarStyle">@style/ActionBarStyle.Transparent</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="ActionBarStyle.Transparent" parent="android:Widget.ActionBar">
<item name="android:background">@null</item>
<item name="android:displayOptions">showHome|showTitle</item>
<item name="android:titleTextStyle">@style/ActionBarStyle.Transparent.TitleTextStyle</item>
</style>
<style name="ActionBarStyle.Transparent.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@android:color/white</item>
</style>
,并给它创建一个可绘制的文件,并添加以下代码添加棉麻织物:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#88000000" />
<gradient
android:angle="90"
android:centerColor="#66000000"
android:centerY="0.3"
android:endColor="#00000000"
android:startColor="#CC000000"
android:type="linear" />
</shape>
,并添加为背景在你的主题中;
没有像以前那样工作,但我绝对会从你的答案中得到一些好的提示。 – Dhruv
不与旧的操作系统选项去,看来你添加一个旧的操作系统选项 –
你是不是指“的minSdkVersion”或“targetSdkVersion '? ....我在Android 6.0设备上测试,谷歌现在的屏幕截图也来自同一设备...我在我的示例应用程序中提到了minSdkVersion为21,targetSdkVersion为23 –