Skip to content

Instantly share code, notes, and snippets.

@imandaliya
Created July 14, 2020 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imandaliya/246cfe01940339610a502b5b6b55d74a to your computer and use it in GitHub Desktop.
Save imandaliya/246cfe01940339610a502b5b6b55d74a to your computer and use it in GitHub Desktop.
public void setThemeTransparentBar(AppCompatActivity activity, AppBarLayout appBarLayout, Toolbar toolbar, RecyclerView recyclerView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (appBarLayout == null || toolbar == null || recyclerView == null) return;
int color = ContextCompat.getColor(activity.getApplicationContext(), R.color.bar_transparent);
appBarLayout.setBackgroundColor(color);
toolbar.setBackgroundColor(Color.TRANSPARENT);
Window window = activity.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
window.setStatusBarColor(color);
window.setNavigationBarColor(color);
CoordinatorLayout.LayoutParams coordinatorLayoutParams = (CoordinatorLayout.LayoutParams) recyclerView.getLayoutParams();
coordinatorLayoutParams.setBehavior(null);
int statusHeight = ViewUtils.getStatusBarHeight(activity);
AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
toolbarLayoutParams.topMargin = statusHeight;
toolbarLayoutParams.setScrollFlags(0);
int top = Utils.dpToPx(activity, 8) + ViewUtils.getActionBarSize(activity) + statusHeight;
int bottom = Utils.dpToPx(activity, 8) + ViewUtils.getNavigationBarHeight(activity.getApplicationContext());
recyclerView.setPadding(recyclerView.getPaddingLeft(), top, recyclerView.getPaddingRight(), bottom);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment