Change Status Bar color when entering Contextual Action Mode

前端 未结 2 2058
予麋鹿
予麋鹿 2020-12-28 17:40

I have an application that uses theme attribute (colorPrimaryDark) to color the Status Bar on Android v21+:

\"en

2条回答
  •  太阳男子
    2020-12-28 17:50

        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); 
            }
            ...
        }
    });
    

提交回复
热议问题