Search code examples
androidaccessibility

Detect "Bold Font" option in accessibility settings programmatically


On some Android devices the user can set "Bold Font" in its accessibility settings. In Pixel 5 this setting is availale in Settings > Accessibility > Text and Display.

I like to know how is it possible to detect is this setting is set. I can't seem to find any relevant part in Android docs. A simliar question exists in StackOverflow for iOS.

Bold text option in Settings > Accessibility > Text and Display


Solution

  • I'm not sure this is what you are looking for, but there is a Field in the configuration class called fontWeightAdjustment that might be what you are looking for. If you do not know how to get that configuration class, you can do this in any activity:

    Configuration config = this.getResources().getConfiguration();
    int fontWeight = config.fontWeightAdjustment;
    

    Note that this field is only available from API level 31 (Android 12). If you want to know more about this field and the configuration class head to the Android documentation