Design principle: Two variables are controlled, date and switch, and then added to the underlying public inheritance Activity class, the global mourning mode can be achieved, and the mourning mode can also be selected on the main interface.
After requesting the data, turn on the switch and save the date
//Mourning pattern code val grayDate = UserConstans.getGrayPatternTime() //Get the saved mourning date val isOpen = UserConstans.getGrayPatternSwitch()//Get the saved mourning switch state if (!TextUtils.isEmpty(grayDate)) { try { val isToday = DateUtil.IsToday(grayDate) if (isToday && isOpen) { val paint = Paint() val colorMatrix = ColorMatrix() colorMatrix.setSaturation(0f) paint.colorFilter = ColorMatrixColorFilter(colorMatrix) window.decorView.setLayerType(View.LAYRD_WARETYPE_HA , paint) } } catch (e: ParseException) { e.printStackTrace() }
In this way, the APP has a global mourning mode. Isn’t it very simple? If you can use it, please give it a like, thank you