【问题标题】:Is there a configChanges for Invert Colors modification是否有用于反转颜色修改的 configChanges
【发布时间】:2020-05-14 00:21:26
【问题描述】:

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

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

但他们都没有处理它。


反转颜色选项:

【问题讨论】:

  • 我在 Android 10 (Pixel 3) 或 Android 9 (Galaxy S9) 的设置中看不到“反转颜色”。您在哪里看到此选项?
  • 感谢您指出这一点!玩它,我怀疑这纯粹是 GPU 的事情,实际上并不是配置更改,但这只是一个猜测。切换时,您的 Activity 是否会发生配置更改?
  • AFAIK, onConfigurationChanged() 只有在您拥有正确的 android:configChanges 属性并选择退出默认配置更改行为时才会被解雇。切换“反转颜色”切换后,您的活动是否被破坏并重新创建?
  • 好的,所以这绝对是配置更改。除非 Logcat 中有一些系统消息,否则我不知道如何确定它是哪种配置更改以及如何通过android:configChanges 选择退出。如果您尝试了所有记录的但没有成功,那么 android:configChanges 值要么未记录,要么不存在(即,您不能选择退出)......而且这些都不是很好的选择。 :-(
  • @CommonsWare 恐怕Android没有颜色反转修改的标志。我使用文档 (mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|density|screenSize|smallestScreenSize) 中可用的所有标志进行了测试,但没有一个使 onConfigurationChanged 回调被触发 =/。无论如何,我要感谢你们的关注、时间和愿意帮助 \o/

标签: android android-manifest onconfigurationchanged


【解决方案1】:

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

手动检查。取自这个问题:
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
    }

您也可以使用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
        }
    }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多