This is very useful to change attributes automatically, without having to change them one by one manually.

Examples:

  • change the Color of all TextViews in a Layout
  • change the TypeFace of all TextViews in a Layout
  • change the Background of all Buttons in a Layout
  • change any attribute of any view in a Layout

The example below changes the color of all TextViews in the Layout.

You can easily change the function to do anything you want. Use the example source code below and change XXXXXX (i.e. TextView, ImageView, Button) and YYYYYY (i.e. setTextColor, setBackground, setBackgroundColor) to anything you want! You may also need to change this function’s second parameter type (int newValue).

If you can think of more examples, please leave a comment below!