简体   繁体   English

是否有用于反转颜色修改的 configChanges

[英]Is there a configChanges for Invert Colors modification

I would like to know if Android has any flag to be added into configChanges in an Activity attribute in the AndroidManifest for modifications in the Invert Colors option of the device.我想知道 Android 是否有任何标志要添加到 AndroidManifest 的 Activity 属性中的configChanges中,以便在设备的“反转颜色”选项中进行修改。

The android doc shows the following flags: - "mcc" android 文档显示了以下标志:-“mcc”
- "mnc" - “跨国公司”
- "locale" - “语言环境”
- "touchscreen" - “触摸屏”
- "keyboard" - “键盘”
- "keyboardHidden" - “键盘隐藏”
- "navigation" - “导航”
- "screenLayout" - “屏幕布局”
- "fontScale" - “字体比例”
- "uiMode" // this one is for the dark mode - "uiMode" // 这是暗模式
- "orientation" - “方向”
- "density" - “密度”
- "screenSize" - “屏幕尺寸”
- "smallestScreenSize" - “最小屏幕尺寸”

But none of them deal with it.但他们都没有处理它。


Invert colors option:反转颜色选项:

在此处输入图片说明

If you need to check the state of inverted colors I see just two possible solutions.如果您需要检查反转颜色的状态,我只会看到两种可能的解决方案。

Manual check.人工检查。 Taken from this question:取自这个问题:
Get enable/disable status and of accessibility Colour inversion mode 获取启用/禁用状态和可访问性颜色反转模式

fun isInversionModeEnabled(): Boolean {
        var isInversionEnabled = false
        val accessibilityEnabled = try {
            Settings.Secure.getInt(contentResolver, Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
        } catch (e: Settings.SettingNotFoundException) {
            Log.d(TAG, "Error finding setting ACCESSIBILITY_DISPLAY_INVERSION_ENABLED: " + e.message)
            Log.d(TAG, "Checking negative color enabled status")
            val SEM_HIGH_CONTRAST = "high_contrast"
            Settings.System.getInt(contentResolver, SEM_HIGH_CONTRAST, 0)
        }
        if (accessibilityEnabled == 1) {
            Log.d(TAG, "inversion  or negative colour is enabled")
            isInversionEnabled = true
        } else {
            Log.d(TAG, "inversion  or negative colour is disabled")
        }
        return isInversionEnabled
    }

And also you can use AccessibilityService .你也可以使用AccessibilityService
On inversion color changed i've got such event:在反转颜色改变时,我有这样的事件:

EventType: TYPE_VIEW_CLICKED; EventTime: 170718119; PackageName: com.android.systemui; 
MovementGranularity: 0; Action: 0; ContentChangeTypes: []; WindowChangeTypes: [] [
ClassName: android.widget.Switch; Text: [Invert colors]; ContentDescription: On;

So i can check the current state somehow like this:所以我可以像这样检查当前状态:

override fun onAccessibilityEvent(event: AccessibilityEvent) {
        val isInvertedColorsChanged = event.text.contains("Invert colors")
        if (isInvertedColorsChanged) {
            val isEnabled = event.contentDescription == "On"
            //do what you need
        }
    }

I'm not sure it will work for every device.我不确定它是否适用于所有设备。
I've never done it before, so maybe there is a better solution.我以前从未这样做过,所以也许有更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM