Search code examples
androidandroid-layoutandroid-viewwai-ariaaccessibility

Android layout resources for Accessibility vision impairment


Android applications currently support different layout resources based on orientation, screen size, day and night etc.

However, I would like to provide layouts targeted at users with vision impairments, for instance use layouts with YELLOW background and BLACK text.

Have I missed something that Android already supports?

Can I implement custom res/layout-WAI or res/layout-DDA folders?


Solution

  • You can't create custom configuration qualifiers. The current supported qualifiers are listed here.

    I will suggest the following workaround (Example):

    1. Create a special layout for WAI for each existing layout, with the same name, but with the suffix "_wai"

      example_layout.xml
      example_layout_wai.xml
      
    2. Create a method to resolve the appropriate layout based on system needs. Say we have a method isWAI(), resolve method will look something like:

      public int resolveLayoutResourceID(int layoutResID) {
          int newLayoutResID = layoutResID;
          if (isWAI()) {
              String layoutResName = getResources().getResourceEntryName(layoutResID);
              String newLayoutResName = layoutResName + "_wai";
              newLayoutResID = getResources().getIdentifier(newLayoutResName, "layout", getPackageName());
          }
          return newLayoutResID;
      }
      
    3. Create a BaseActivity class for all your classes (or use a utility static function), that will override the setContentView method. There you will add a logic to select the layout.

      @Override
      public void setContentView(int layoutResID) {
          int newLayoutResID = resolveLayoutResourceID(layoutResID)
          super.setContentView(newLayoutResID);
      }