如何检测辅助功能设置中是否启用了“高对比度”设置(在Android 5.0+上可用)?
答案 0 :(得分:2)
在AccessibilityManager
班级(see source here)中,您有一个名为isHighTextContrastEnabled
的公共方法,可用于获取您的信息:
/**
* 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;
}
}
因此,在您的代码中,您可以通过这样做来访问此方法(如果您在Activity
中):
AccessibilityManager am = (AccessibilityManager) this.getSystemService(Context.ACCESSIBILITY_SERVICE);
boolean isHighTextContrastEnabled = am.isHighTextContrastEnabled();
答案 1 :(得分:1)
如果在用户手机中启用了 HighContrastText,则下面的函数将返回 true,否则返回 false。
<块引用>以下功能已在所有 Android 手机中检查并正常工作。
public static boolean isHighContrastTextEnabled(Context context) {
if (context != null) {
AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
Method m = null;
if (am != null) {
try {
m = am.getClass().getMethod("isHighTextContrastEnabled", null);
} catch (NoSuchMethodException e) {
Log.i("FAIL", "isHighTextContrastEnabled not found in AccessibilityManager");
}
}
Object result;
if (m != null) {
try {
result = m.invoke(am, null);
if (result instanceof Boolean) {
return (Boolean) result;
}
} catch (Exception e) {
Log.i("fail", "isHighTextContrastEnabled invoked with an exception" + e.getMessage());
}
}
}
return false;
}
<块引用>
<块引用>
我希望这可以帮助更多人。