目前,我正在遵循https://stackoverflow.com/a/29748810/72437的建议,以便在进入上下文操作模式时更改状态栏颜色。
但是,从以下视频https://www.youtube.com/watch?v=2Ra56_eh7uk中,我们可以观察到状态栏总是会发生颜色变化,然后工具栏上的颜色才会随之变化。
有什么方法可以在状态栏和工具栏上同时发生颜色变化。
@SuppressLint("NewApi")
private class ModeCallback implements ListView.MultiChoiceModeListener {
public boolean onCreateActionMode(android.view.ActionMode mode,
android.view.Menu menu) {
...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Activity activity = getActivity();
if (activity != null) {
activity.getWindow().setStatusBarColor(actionModeStatusBarColor);
}
}
return true;
}
public boolean onPrepareActionMode(android.view.ActionMode mode, android.view.Menu menu) {
return true;
}
public boolean onActionItemClicked(android.view.ActionMode mode, android.view.MenuItem item) {
switch (item.getItemId()) {
....
}
return false;
}
public void onDestroyActionMode(android.view.ActionMode mode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Activity activity = getActivity();
if (activity != null) {
activity.getWindow().setStatusBarColor(colorPrimaryDark);
}
}
}
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
this.getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
this.getListView().setMultiChoiceModeListener(new ModeCallback());
...