Android apk 哀悼模式 主要设置

设计原理:两个变量控制 ,日期 和开关,然后添加到底层公共继承Activity类里面,就能做到全局哀悼模式,也可以选择主要界面选择设置哀悼模式。

当请求到数据后 打开开关和保存日期

//悼念模式代码
val grayDate = UserConstans.getGrayPatternTime() //获取保存的 哀悼日期
val isOpen = UserConstans.getGrayPatternSwitch()//获取保存的 哀悼开关状态
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.LAYER_TYPE_HARDWARE, paint)
        }
    } catch (e: ParseException) {
        e.printStackTrace()
    }

这样就做到 APP全局哀悼模式了,是不是很简单!如果能用的上,就点个赞吧,感谢

猜你喜欢

转载自blog.csdn.net/qq_25462179/article/details/128216043