我有这样的渐变值:linear-gradient(to right, #0072FF,#00C6FF)
。你能告诉我如何将它应用到Android status bar吗?
我试过如下图所示。但它没有用。
this.statusBar.backgroundColorByHexString('linear-gradient(to right, #0072FF,#00C6FF)');
这种简单的工作正常:
this.statusBar.backgroundColorByHexString('#0072FF');
答案 0 :(得分:0)
你可以使用半透明状态栏并将gradian背景设置为具有相同高度的状态栏布局。
用于设置状态栏Translucent将此行添加到您的主题:
<item name="android:windowTranslucentStatus">true</item>
答案 1 :(得分:0)
您可以像这样设置背景颜色渐变:
Window window = activity.getWindow();
Drawable background = activity.getResources().getDrawable(R.drawable.gradient_theme);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(activity.getResources().getColor(R.color.transparent));
window.setNavigationBarColor(activity.getResources().getColor(R.color.transparent));
window.setBackgroundDrawable(background);
但它适用于api 21和更大的
你的渐变主题在drawables中应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="@color/colorPrimary"
android:endColor="@color/color_primary_100"
android:type="linear" />
</shape>
</item>
</selector>