From 35471fafffa16d135437fc24d33e6fbfcd301816 Mon Sep 17 00:00:00 2001 From: niorgai Date: Sat, 4 Mar 2017 00:14:36 +0800 Subject: [PATCH] fix issue #15 --- README.md | 2 +- build.gradle | 2 +- .../java/qiu/niorgai/StatusBarCompatKitKat.java | 13 ++++++++----- .../java/qiu/niorgai/StatusBarCompatLollipop.java | 8 +++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index efb5104..296725f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Add the dependency ```groovy dependencies { - compile ('com.github.niorgai:StatusBarCompat:2.1.2', { + compile ('com.github.niorgai:StatusBarCompat:2.1.3', { exclude group: 'com.android.support' }) } diff --git a/build.gradle b/build.gradle index 511b8e2..0de3ab2 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { ] libs = [ - supportVersion : "25.1.0" + supportVersion : "25.2.0" ] } diff --git a/library/src/main/java/qiu/niorgai/StatusBarCompatKitKat.java b/library/src/main/java/qiu/niorgai/StatusBarCompatKitKat.java index f9b8360..585176c 100644 --- a/library/src/main/java/qiu/niorgai/StatusBarCompatKitKat.java +++ b/library/src/main/java/qiu/niorgai/StatusBarCompatKitKat.java @@ -153,9 +153,10 @@ static void translucentStatusBar(Activity activity) { * * 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS * 2. set FitsSystemWindows for views. - * 3. removeFakeStatusBarViewIfExist - * 4. removeMarginTopOfContentChild - * 5. add OnOffsetChangedListener to change statusBarView's alpha + * 3. add Toolbar's height, let it layout from top, then add paddingTop to layout normal. + * 4. removeFakeStatusBarViewIfExist + * 5. removeMarginTopOfContentChild + * 6. add OnOffsetChangedListener to change statusBarView's alpha */ static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, int statusColor) { @@ -170,11 +171,13 @@ static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBa collapsingToolbarLayout.setFitsSystemWindows(false); collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false); - toolbar.setFitsSystemWindows(true); + toolbar.setFitsSystemWindows(false); if (toolbar.getTag() == null) { CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); - lp.height += getStatusBarHeight(activity); + int statusBarHeight = getStatusBarHeight(activity); + lp.height += statusBarHeight; toolbar.setLayoutParams(lp); + toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom()); toolbar.setTag(true); } diff --git a/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java b/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java index 4ad2bc4..d4edcd0 100644 --- a/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java +++ b/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java @@ -95,7 +95,7 @@ static void translucentStatusBar(Activity activity, boolean hideStatusBarBackgro * 1. change to full-screen mode(like translucentStatusBar). * 2. cancel CollapsingToolbarLayout's WindowInsets, let it layout as normal(now setStatusBarScrimColor is useless). * 3. set View's FitsSystemWindow to false. - * 4. adjust toolbar's height to layout. + * 4. add Toolbar's height, let it layout from top, then add paddingTop to layout normal. * 5. change statusBarColor by AppBarLayout's offset. * 6. add Listener to change statusBarColor */ @@ -125,11 +125,13 @@ public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) ((View) appBarLayout.getParent()).setFitsSystemWindows(false); appBarLayout.setFitsSystemWindows(false); - toolbar.setFitsSystemWindows(true); + toolbar.setFitsSystemWindows(false); if (toolbar.getTag() == null) { CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams(); - lp.height += getStatusBarHeight(activity); + int statusBarHeight = getStatusBarHeight(activity); + lp.height += statusBarHeight; toolbar.setLayoutParams(lp); + toolbar.setPadding(toolbar.getPaddingLeft(), toolbar.getPaddingTop() + statusBarHeight, toolbar.getPaddingRight(), toolbar.getPaddingBottom()); toolbar.setTag(true); }