caipivara
5/19/2015 - 2:25 AM

Android - set toolbar and status bar and navigation bar background color

Android - set toolbar and status bar and navigation bar background color

protected void setStyleColor(int textColor, int backgroundColor, int backgroundColorDark) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
	    Window window = getWindow();
	
	    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
	    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
	
	    window.setStatusBarColor(backgroundColorDark);
	    window.setNavigationBarColor(backgroundColorDark);
	}
	
	for (int i = 0; i < mToolbar.getChildCount(); i++) {
	    View v = mToolbar.getChildAt(i);
	    if (v != null && v instanceof TextView) {
	        TextView t = (TextView) v;
	        t.setBackgroundColor(backgroundColor);
	    }
	}
	
	//        Drawable upArrow = mToolbar.getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
	//        upArrow.setColorFilter(textColor, PorterDuff.Mode.SRC_IN);
	
	mToolbar.setTitleTextColor(textColor);
	mToolbar.setBackgroundColor(backgroundColor);
	mToolbar.setDrawingCacheBackgroundColor(backgroundColor);
}