如何将状态栏背景设置为渐变颜色或android中的drawable

我想将状态栏背景设置为渐变主题,状态栏和动作栏颜色应该是相同的渐变可绘制,根据文档,我们可以使用API​​级别21及以上的状态栏将颜色设置为使用

<item name="android:statusBarColor">@color/colorPrimary</item>

但我正在寻找类似的东西

<item name="android:statusBarDrawable">@drawable/myDrawable</item>

我见过使用的例子

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

但在那种情况下状态栏和操作栏重叠(使用fitSystemWindow = true但仍未解决)也尝试使用https://github.com/jgilfelt/SystemBarTint这个库但仍然没有运气

先感谢您!!

解决方法:

enter image description here

对于想要将渐变颜色设置为状态栏背景的人,可以在setContentView()之前在活动中使用以下方法

 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void setStatusBarGradiant(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            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(android.R.color.transparent));
            window.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent));
            window.setBackgroundDrawable(background);
        }
    } 

感谢每一位人士的帮助

编辑

如果上面的代码不起作用,请尝试在styles.xml中添加

<style name="AppTheme.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...