Created
July 14, 2020 06:24
-
-
Save imandaliya/246cfe01940339610a502b5b6b55d74a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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