美文网首页
设置渐变色 StatusBar

设置渐变色 StatusBar

作者: zac4j | 来源:发表于2017-09-19 19:06 被阅读190次

    SystemBarTintManager 实现很简单,就几行代码:

    private void tintStatusBar(@NonNull Activity activity, @ColorInt int startColor, @ColorInt int endColor) {
        Window window = activity.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
          window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
          window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
          window.setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
          window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        GradientDrawable drawable =
            new GradientDrawable(LEFT_RIGHT, new int[] { startColor, endColor });
    
        final SystemBarTintManager tintManager = new SystemBarTintManager(this);
        // enable status bar tint
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setNavigationBarTintEnabled(false);
        tintManager.setTintDrawable(drawable);
      }
    

    相关文章

      网友评论

          本文标题:设置渐变色 StatusBar

          本文链接:https://www.haomeiwen.com/subject/aiobsxtx.html