You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在启动器应用中实现Color Correction设置的启停与调整?

How to Implement Color Correction Controls in Your Launcher App

Hey there! I’ve built a few custom launchers and tackled this exact color correction feature before—let me break down how to pull it off, step by step.

First off, color correction is a system-level display adjustment, so we’ll leverage Android’s built-in APIs instead of reinventing the wheel (which would be inefficient and inconsistent with the user’s system experience).

1. Grab the Required Permissions

First, add these permissions to your AndroidManifest.xml—you’ll need them to modify system display settings:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESSIBILITY_SETTINGS" />

Important note: The WRITE_SETTINGS permission can’t be granted automatically. You’ll need to prompt users to enable it manually via the system settings. Here’s how to trigger that:

if (!Settings.System.canWrite(context)) {
    val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
    intent.data = Uri.parse("package:" + context.packageName)
    startActivity(intent)
}

2. Toggle Color Correction On/Off

Android stores color correction preferences in Settings.Secure. You can read/write these values to control the feature:

  • The main toggle uses the key ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED (1 = on, 0 = off)
  • For colorblind modes, use ACCESSIBILITY_DISPLAY_DALTONIZER (values: 0 = off, 1 = red-green deficiency, 2 = blue-yellow deficiency, 3 = total color blindness)

Example code to enable red-green color correction:

// Turn on color correction
Settings.Secure.putInt(context.contentResolver, 
    Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1)
// Set to red-green colorblind mode
Settings.Secure.putInt(context.contentResolver,
    Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, 1)

To turn it off, just set ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED to 0.

3. Fine-Tune Custom Parameters (Advanced)

If you want to let users adjust things like color temperature, saturation, or contrast, here’s how to handle it based on Android version:

Android 12+ (API 31+)

Google introduced ColorDisplayManager in Android 12, which makes this super straightforward:

val colorDisplayManager = context.getSystemService(ColorDisplayManager::class.java)
// Enable custom color adjustments
colorDisplayManager.setAdjustmentEnabled(true)
// Set color temperature (range: 1000–10000; lower = warmer, higher = cooler)
colorDisplayManager.setColorTemperature(6500)
// Set saturation (range: 0–2; 1 = default, 0 = grayscale, 2 = high saturation)
colorDisplayManager.setSaturation(1.5f)

Android 7–11 (API 24–30)

For older versions, you’ll need to work with system settings directly. Note that some manufacturers use custom keys for these values, so test across devices. For example, you can adjust screen temperature using:

// Adjust color temperature (value range varies by manufacturer)
Settings.System.putInt(context.contentResolver,
    Settings.System.SCREEN_COLOR_TEMPERATURE, 6500)

Just keep in mind that these values might not be consistent across all brands.

4. Build the UI for Your Settings

In your launcher’s settings screen, add these user-friendly controls:

  • A SwitchCompat to toggle color correction on/off
  • A RadioGroup to let users select colorblind modes
  • SeekBar widgets to adjust temperature, saturation, etc., with real-time previews

5. Compatibility Tips

  • Different manufacturers tweak system settings keys, so test your code on multiple devices (Samsung, Google Pixel, Xiaomi, etc.)
  • Android 13+ has updated permission logic, so double-check your permission flow for newer OS versions
  • Avoid overriding system settings without clear user consent—always let users know what changes you’re making

内容的提问来源于stack exchange,提问作者Ali Mohtashim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:03:06