进入上下文操作模式时,请更改状态栏颜色 [英] Change Status Bar color when entering Contextual Action Mode
问题描述
我有一个使用theme属性(colorPrimaryDark)上色在Android V21的状态栏的应用程序+:
这是工作的罚款。现在,当用户长期presses一个列表项,进入情境操作模式中,我能够使用属性颜色的CAB条actionModeBackground,所以它看起来是这样的:
因此,操作栏是灰色的,这就是我想要的,但状态栏使用主题深色还是有色。我不希望这样,我希望将它更改为深灰色或黑色。
我怎样才能做到这一点?我没有看到任何主题的属性,将在这里工作。
私人诠释statusBarColor;
@覆盖
公共布尔onCreateActionMode(ActionMode模式,菜单菜单){
如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.LOLLIPOP){
//持有状态栏当前的颜色
statusBarColor = getWindow()getStatusBarColor()。
//设置你的灰色
。getWindow()setStatusBarColor(0xFF555555);
}
...
}
...
@覆盖
公共无效onDestroyActionMode(ActionMode模式){
如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.LOLLIPOP){
//返回到状态栏的老色
。getWindow()setStatusBarColor(statusBarColor);
}
...
}
});
I have an application that uses theme attribute (colorPrimaryDark) to color the Status Bar on Android v21+:
This is working fine. Now, when user long-presses a list item and enters the contextual action mode, I am able to color the CAB bar using attribute actionModeBackground so it looks like this:
So the action bar is gray, which is what I want, but the status bar is still colored using the theme dark color. I don't want that, I want to change it to dark gray or black.
How can I do this? I don't see any theme attribute that would work here.
private int statusBarColor;
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//hold current color of status bar
statusBarColor = getWindow().getStatusBarColor();
//set your gray color
getWindow().setStatusBarColor(0xFF555555);
}
...
}
...
@Override
public void onDestroyActionMode(ActionMode mode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//return to "old" color of status bar
getWindow().setStatusBarColor(statusBarColor);
}
...
}
});
这篇关于进入上下文操作模式时,请更改状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!