Henry
Henry

Reputation: 2650

In Android, what is the best way to define small tweaks to my style.xml or dimens.xml?

In Android, we can specify resources depending on the screen size by appending qualifiers to the folder names, such as "res/values-xlarge". I am working on a large enterprise application that has some fairly big styles.xml and dimens.xml files. Obviously, I do not want to duplicate the entire files for each screen size that needs some small tweaks.

What is the best way to specify tweaks to styles, dimens, and similar resources without duplicating the common parts?

Upvotes: 1

Views: 135

Answers (1)

Charlie-Blake
Charlie-Blake

Reputation: 11050

Just specify the values you want to modify in the different folders, and leave the common ones on the lowest level. Styles will be a bit harder to do, but you can actually make a common style with all common values, then specify the differences in a different style that inherits from the first one.

For example, you can have a style A in res/values/ that has the common behaviour for all the different styles. However, in large screens (hdpi and xhdpi) you want to have a common behaviour you don't want in little screens: Just create a B style that inherits from A and has that behaviour in res/values, then specify the differences in res/values-xhdpi and res/values-hdpi.

If Android cannot find a value in R in a "proper" folder, it will search elsewhere until it finds said value.

Upvotes: 1

Related Questions