繁体   English   中英

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

[英]Is there a configChanges for Invert Colors modification

我想知道 Android 是否有任何标志要添加到 AndroidManifest 的 Activity 属性中的configChanges中,以便在设备的“反转颜色”选项中进行修改。

android 文档显示了以下标志:-“mcc”
- “跨国公司”
- “语言环境”
- “触摸屏”
- “键盘”
- “键盘隐藏”
- “导航”
- “屏幕布局”
- “字体比例”
- "uiMode" // 这是暗模式
- “方向”
- “密度”
- “屏幕尺寸”
- “最小屏幕尺寸”

但他们都没有处理它。


反转颜色选项:

在此处输入图片说明

如果您需要检查反转颜色的状态,我只会看到两种可能的解决方案。

人工检查。 取自这个问题:
获取启用/禁用状态和可访问性颜色反转模式

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
    }

你也可以使用AccessibilityService
在反转颜色改变时,我有这样的事件:

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;

所以我可以像这样检查当前状态:

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

我不确定它是否适用于所有设备。
我以前从未这样做过,所以也许有更好的解决方案。

暂无
暂无

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

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