Detect if 'High contrast' is enabled in Android accessibility settings

心已入冬 提交于 2019-12-19 10:32:13

问题


How can I detect if 'High Contrast' setting (available on Android 5.0+) is enabled in Accessibility settings?


回答1:


In the AccessibilityManager class (see source here) you have a public method called isHighTextContrastEnabled that you can use to get your information:

/**
 * Returns if the high text contrast in the system is enabled.
 * <p>
 * <strong>Note:</strong> You need to query this only if you application is
 * doing its own rendering and does not rely on the platform rendering pipeline.
 * </p>
 *
 * @return True if high text contrast is enabled, false otherwise.
 *
 * @hide
 */
public boolean isHighTextContrastEnabled() {
    synchronized (mLock) {
        IAccessibilityManager service = getServiceLocked();
        if (service == null) {
            return false;
        }
        return mIsHighTextContrastEnabled;
    }
}

So in your code, you can access this method by doing so (if you're in an Activity):

AccessibilityManager am = (AccessibilityManager) this.getSystemService(Context.ACCESSIBILITY_SERVICE);
boolean isHighTextContrastEnabled = am.isHighTextContrastEnabled();


来源:https://stackoverflow.com/questions/34411712/detect-if-high-contrast-is-enabled-in-android-accessibility-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!