Change Status Bar color when entering Contextual Action Mode

前端 未结 2 2038
予麋鹿
予麋鹿 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); 
            }
            ...
        }
    });
    
    0 讨论(0)
  • 2020-12-28 17:57

    Place it on your Application theme(both style.xml and v21 style.xml) or create custom theme for where you want to change.

    <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light">
            <item name="colorPrimary">@color/color_primary</item>
            <item name="colorPrimaryDark">@color/color_secondary</item>
            <item name="colorAccent">@color/color_accent</item>
            **<item name="android:statusBarColor">@color/**YOUR_COLOR**</item>**
        </style>
    </resources>

    0 讨论(0)
提交回复
热议问题