設(shè)置漸變色 StatusBar

SystemBarTintManager 實現(xiàn)很簡單,就幾行代碼:

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);
  }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,552評論 25 708
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,255評論 4 61
  • 我也想做一個狠心的人,我也想變成我厭惡的人 這樣我或許能過的比現(xiàn)在好很多 擁有更多 可怎奈我有一顆琉璃心,我想要那...
    乙木々閱讀 216評論 0 0
  • 為了能夠讓自己孩子的成績在有限的時間得到最大的提升,很多家長選擇了給孩子找一對一的老師或者是家教,幫助孩子在學(xué)習(xí)方...
    gaosijiaoyu閱讀 552評論 0 0