Skip to content

Commit d3ce9ca

Browse files
committed
see 08/01 log
1 parent e62c3df commit d3ce9ca

File tree

7 files changed

+102
-55
lines changed

7 files changed

+102
-55
lines changed

app/src/main/java/com/blankj/androidutilcode/activity/MainActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public int bindLayout() {
3636
@Override
3737
public void initView(Bundle savedInstanceState, View view) {
3838
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
39-
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.ctl);
40-
collapsingToolbarLayout.setExpandedTitleColor(Color.parseColor("#00FFFFFF"));
39+
View fakeStatusBar = findViewById(R.id.fake_status_bar);
40+
CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.ctl);
41+
ctl.setExpandedTitleColor(Color.parseColor("#00FFFFFF"));
4142
setSupportActionBar(toolbar);
4243
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
4344
rootLayout,
@@ -47,7 +48,7 @@ public void initView(Bundle savedInstanceState, View view) {
4748
rootLayout.addDrawerListener(toggle);
4849
toggle.syncState();
4950

50-
BarUtils.setStatusBarAlpha(this, 0);
51+
BarUtils.setStatusBarAlpha4Drawer(this, rootLayout, fakeStatusBar, 0, false);
5152
BarUtils.addMarginTopEqualStatusBarHeight(toolbar);
5253
}
5354

app/src/main/java/com/blankj/androidutilcode/activity/StatusBarDrawerActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public void initView(Bundle savedInstanceState, View view) {
7272

7373
tvStatusAlpha.setText(String.valueOf(mAlpha));
7474

75-
7675
updateStatusBar();
7776
}
7877

@@ -129,7 +128,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
129128
};
130129

131130
private void updateStatusBar() {
132-
BarUtils.setStatusBarAlpha(this, mAlpha);
131+
BarUtils.setStatusBarAlpha(this, 0);
132+
// BarUtils.setStatusBarColor4Drawer(this, rootLayout, fakeStatusBar, mColor, mAlpha, true);
133+
133134
// if (!cbAlpha.isChecked()) {
134135
//// BarUtils.setStatusBarColor(this, mColor, mAlpha);
135136
// BarUtils.setFakeStatusBarColor(fakeStatusBar, mColor, mAlpha);

app/src/main/java/com/blankj/androidutilcode/base/BaseDrawerActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
public abstract class BaseDrawerActivity extends BaseActivity {
2424

2525
protected DrawerLayout rootLayout;
26+
protected FrameLayout flActivityContainer;
2627

2728
NavigationView.OnNavigationItemSelectedListener mListener = new NavigationView.OnNavigationItemSelectedListener() {
2829
@Override
@@ -44,8 +45,8 @@ protected void setBaseView() {
4445
contentView = LayoutInflater.from(this).inflate(R.layout.activity_drawer, null);
4546
setContentView(contentView);
4647
rootLayout = (DrawerLayout) findViewById(R.id.root_layout);
47-
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.activity_container);
48-
frameLayout.addView(LayoutInflater.from(this).inflate(bindLayout(), frameLayout, false));
48+
flActivityContainer = (FrameLayout) findViewById(R.id.activity_container);
49+
flActivityContainer.addView(LayoutInflater.from(this).inflate(bindLayout(), flActivityContainer, false));
4950
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
5051
navigationView.setNavigationItemSelectedListener(mListener);
5152
}

app/src/main/res/layout/activity_drawer.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
android:layout_height="wrap_content" />
1717

1818
<android.support.design.widget.NavigationView
19+
android:fitsSystemWindows="false"
1920
android:id="@+id/nav_view"
2021
android:layout_width="wrap_content"
2122
android:layout_height="match_parent"

app/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
</android.support.design.widget.CollapsingToolbarLayout>
3737
</android.support.design.widget.AppBarLayout>
3838

39+
<View
40+
android:id="@+id/fake_status_bar"
41+
android:layout_width="match_parent"
42+
android:layout_height="0dp" />
43+
3944
<android.support.v4.widget.NestedScrollView
4045
android:layout_width="match_parent"
4146
android:layout_height="match_parent"

app/src/main/res/layout/activity_status_bar_drawer.xml

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,63 @@
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent">
7+
<LinearLayout
8+
xmlns:android="http://schemas.android.com/apk/res/android"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:gravity="center_horizontal"
12+
android:orientation="vertical">
13+
14+
<View
15+
android:id="@+id/fake_status_bar"
16+
android:layout_width="match_parent"
17+
android:layout_height="0dp" />
718

819
<LinearLayout
9-
xmlns:android="http://schemas.android.com/apk/res/android"
1020
android:layout_width="match_parent"
1121
android:layout_height="wrap_content"
1222
android:gravity="center_horizontal"
13-
android:orientation="vertical">
23+
android:orientation="vertical"
24+
android:paddingLeft="@dimen/spacing_16"
25+
android:paddingRight="@dimen/spacing_16">
1426

15-
<View
16-
android:id="@+id/fake_status_bar"
17-
android:layout_width="match_parent"
18-
android:layout_height="0dp" />
19-
20-
<LinearLayout
21-
android:layout_width="match_parent"
27+
<CheckBox
28+
android:id="@+id/cb_alpha"
29+
android:layout_width="wrap_content"
2230
android:layout_height="wrap_content"
23-
android:gravity="center_horizontal"
24-
android:orientation="vertical"
25-
android:paddingLeft="@dimen/spacing_16"
26-
android:paddingRight="@dimen/spacing_16">
27-
28-
<CheckBox
29-
android:id="@+id/cb_alpha"
30-
android:layout_width="wrap_content"
31-
android:layout_height="wrap_content"
32-
android:layout_gravity="center_horizontal"
33-
android:layout_margin="4dp"
34-
android:text="@string/status_bar_title_alpha" />
31+
android:layout_gravity="center_horizontal"
32+
android:layout_margin="4dp"
33+
android:text="@string/status_bar_title_alpha" />
3534

36-
<TextView
37-
android:id="@+id/tv_status_alpha"
38-
style="@style/TextStyle"
39-
android:layout_width="wrap_content"
40-
android:layout_height="wrap_content"
41-
android:layout_gravity="center_horizontal" />
35+
<TextView
36+
android:id="@+id/tv_status_alpha"
37+
style="@style/TextStyle"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_gravity="center_horizontal" />
4241

43-
<SeekBar
44-
android:id="@+id/sb_change_alpha"
45-
android:layout_width="match_parent"
46-
android:layout_height="wrap_content"
47-
android:max="255"
48-
android:padding="@dimen/spacing_8"
49-
android:progress="112" />
42+
<SeekBar
43+
android:id="@+id/sb_change_alpha"
44+
android:layout_width="match_parent"
45+
android:layout_height="wrap_content"
46+
android:max="255"
47+
android:padding="@dimen/spacing_8"
48+
android:progress="112" />
5049

51-
<Button
52-
android:id="@+id/btn_random_color"
53-
style="@style/WideBtnStyle"
54-
android:layout_width="match_parent"
55-
android:layout_height="wrap_content"
56-
android:text="@string/status_bar_random_color" />
50+
<Button
51+
android:id="@+id/btn_random_color"
52+
style="@style/WideBtnStyle"
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content"
55+
android:text="@string/status_bar_random_color" />
5756

58-
<Button
59-
android:id="@+id/btn_set_transparent"
60-
style="@style/WideBtnStyle"
61-
android:layout_width="match_parent"
62-
android:layout_height="wrap_content"
63-
android:text="@string/status_bar_set_transparent" />
57+
<Button
58+
android:id="@+id/btn_set_transparent"
59+
style="@style/WideBtnStyle"
60+
android:layout_width="match_parent"
61+
android:layout_height="wrap_content"
62+
android:text="@string/status_bar_set_transparent" />
6463

65-
</LinearLayout>
6664
</LinearLayout>
67-
</android.support.design.widget.CoordinatorLayout>
65+
</LinearLayout>
66+
</android.support.design.widget.CoordinatorLayout>

utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public static void setFakeStatusBarColor(@NonNull final View fakeStatusBar,
207207
fakeStatusBar.setVisibility(View.VISIBLE);
208208
transparentStatusBar((Activity) fakeStatusBar.getContext());
209209
ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
210+
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
210211
layoutParams.height = BarUtils.getStatusBarHeight();
211212
fakeStatusBar.setBackgroundColor(getStatusBarColor(color, alpha));
212213
}
@@ -232,10 +233,48 @@ public static void setFakeStatusBarAlpha(@NonNull final View fakeStatusBar,
232233
fakeStatusBar.setVisibility(View.VISIBLE);
233234
transparentStatusBar((Activity) fakeStatusBar.getContext());
234235
ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
236+
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
235237
layoutParams.height = BarUtils.getStatusBarHeight();
236238
fakeStatusBar.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
237239
}
238240

241+
public static void setStatusBarColor4Drawer(@NonNull final Activity activity,
242+
@NonNull final DrawerLayout drawer,
243+
@NonNull final View fakeStatusBar,
244+
@ColorInt final int color,
245+
@IntRange(from = 0, to = 255) final int alpha,
246+
final boolean isShowShaderInDrawer) {
247+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
248+
transparentStatusBar(activity);
249+
setFakeStatusBarColor(fakeStatusBar, color, alpha);
250+
for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
251+
drawer.getChildAt(i).setFitsSystemWindows(false);
252+
}
253+
if (isShowShaderInDrawer) addStatusBarAlpha(activity, alpha, false);
254+
}
255+
256+
public static void setStatusBarAlpha4Drawer(@NonNull final Activity activity,
257+
@NonNull final DrawerLayout drawer,
258+
@NonNull final View fakeStatusBar,
259+
final boolean isShowShaderInDrawer) {
260+
setStatusBarAlpha4Drawer(activity, drawer, fakeStatusBar, DEFAULT_ALPHA, isShowShaderInDrawer);
261+
}
262+
263+
public static void setStatusBarAlpha4Drawer(@NonNull final Activity activity,
264+
@NonNull final DrawerLayout drawer,
265+
@NonNull final View fakeStatusBar,
266+
@IntRange(from = 0, to = 255) final int alpha,
267+
final boolean isShowShaderInDrawer) {
268+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
269+
transparentStatusBar(activity);
270+
setFakeStatusBarAlpha(fakeStatusBar, alpha);
271+
for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
272+
drawer.getChildAt(i).setFitsSystemWindows(false);
273+
}
274+
if (isShowShaderInDrawer) addStatusBarAlpha(activity, alpha, false);
275+
}
276+
277+
239278
/**
240279
* 隐藏伪状态栏 View
241280
*

0 commit comments

Comments
 (0)