Skip to content

Commit a3107cb

Browse files
committed
DemoMain:选择颜色后状态栏和导航栏一起变色
1 parent d21e842 commit a3107cb

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

ZBLibrary(AndroidStudio)/app/src/main/java/zblibrary/demo/DEMO/DemoMainActivity.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import zblibrary.demo.activity.ScanActivity;
3737
import zuo.biao.library.base.BaseActivity;
3838
import zuo.biao.library.interfaces.OnBottomDragListener;
39+
import zuo.biao.library.manager.SystemBarTintManager;
3940
import zuo.biao.library.ui.AlertDialog;
4041
import zuo.biao.library.ui.AlertDialog.OnDialogButtonClickListener;
4142
import zuo.biao.library.ui.BottomMenuWindow;
@@ -119,6 +120,23 @@ public void initView() {//必须调用
119120
svDemoMain = findView(R.id.svDemoMain);
120121
}
121122

123+
/**设置沉浸状态栏和导航栏颜色
124+
* @param position
125+
*/
126+
private void setTintColor(int position) {
127+
if (position < 0) {
128+
position = 0;
129+
} else if (position >= TOPBAR_COLOR_RESIDS.length) {
130+
position = TOPBAR_COLOR_RESIDS.length - 1;
131+
}
132+
133+
rlDemoMainTopbar.setBackgroundResource(TOPBAR_COLOR_RESIDS[position]);
134+
135+
SystemBarTintManager tintManager = new SystemBarTintManager(this);
136+
tintManager.setStatusBarTintEnabled(true);
137+
tintManager.setStatusBarTintResource(TOPBAR_COLOR_RESIDS[position]);//状态背景色,可传drawable资源
138+
}
139+
122140
/**显示列表选择弹窗
123141
*/
124142
private void showItemDialog() {
@@ -270,16 +288,14 @@ public void onDialogItemClick(int requestCode, int position, String item) {
270288
}
271289
switch (requestCode) {
272290
case DIALOG_SET_TOPBAR:
273-
if (position >= TOPBAR_COLOR_RESIDS.length) {
274-
position = TOPBAR_COLOR_RESIDS.length - 1;
275-
}
276-
rlDemoMainTopbar.setBackgroundResource(TOPBAR_COLOR_RESIDS[position]);
291+
setTintColor(position);
277292
break;
278293
default:
279294
break;
280295
}
281296
}
282297

298+
283299
@Override
284300
public void onDragBottom(boolean rightToLeft) {
285301
if (rightToLeft) {
@@ -499,9 +515,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
499515
break;
500516
case REQUEST_TO_BOTTOM_MENU:
501517
if (data != null) {
502-
int selectedPosition = data.getIntExtra(BottomMenuWindow.RESULT_ITEM_ID, -1);
503-
if (selectedPosition >= 0 && selectedPosition < TOPBAR_COLOR_RESIDS.length) {
504-
rlDemoMainTopbar.setBackgroundResource(TOPBAR_COLOR_RESIDS[selectedPosition]);
518+
int position = data.getIntExtra(BottomMenuWindow.RESULT_ITEM_ID, -1);
519+
if (position >= 0) {
520+
setTintColor(position);
505521
}
506522
}
507523
break;

0 commit comments

Comments
 (0)