[英]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.