Answer the question
In order to leave comments, you need to log in
Android. How to organize the choice of styles in the application?
A banal thought was born: to make the application the ability to change styles. Those. the user selected in the menu, from the list "Orange" - once, and everything became in shades of orange. I chose "Blue" - it became blue. Created several styles, with different coloring. And the question arose, how to organize the filling of the menu? It turned out like this:
menu.add(R.id.themesMenuGroup, R.style.AppThemeBlack, 0, R.string.AppThemeBlackName);
menu.add(R.id.themesMenuGroup, R.style.AppThemeBrown, 0, R.string.AppThemeBrownName);
menu.add(R.id.themesMenuGroup, R.style.AppThemeAmber, 0, R.string.AppThemeAmberName);
// ------- еще много аналогичных строк выброшено для экономии места -----------
Answer the question
In order to leave comments, you need to log in
Make an array with styles and strings
and loop add
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="styleNames">
<item>@string/AppThemeBlackName</item>
<item>@string/AppThemeBrownName</item>
<item>@string/AppThemeAmberName</item>
</array>
<!-- можно написать так -->
<string-array name="styleNames1">
<item>Черный</item>
<item>Коричневый</item>
<item>Оранжевый</item>
</string-array>
<integer-array name="styleIDs">
<item>@style/AppThemeBlack</item>
<item>@style/AppThemeBrown</item>
<item>@style/AppThemeAmber</item>
</integer-array>
</resources>
String[] names = getResources().getStringArray(R.array.styleNames);
int[] ids= getResources().getIntArray(R.array.styleIDs);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question