Yêu cầu thg 8 28, 2018 8:23 SA 476 0 1
  • 476 0 1
0

set status bar background as gradien Android

Chia sẻ
  • 476 0 1

Mọi người cho mình hỏi làm cách nào để set color cho status bar bằng gradien được không a.? mình muốn set status trùng màu với toolbar .màu ở toolbar là mình trộn giữa 2 màu ạ.

1 CÂU TRẢ LỜI


Đã trả lời thg 10 1, 2018 4:15 CH
+1

Gọi hàm này trước khi setContentView , cách này chỉ hoạt động khi API > 21

 @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);
        }
    } 
Chia sẻ
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí