There is any way to declare variables (using product flavors) in the build.gradle that can be substituted in the styles.xml of my Android application? I want provide custom fonts for each product flavor i use for the application like this approach:
Is it possible to declare a variable in Gradle usable in Java?
And you have some styles that depend on the value of the variable:
<style name="my-android-style">
<item name="font_file_name">MY_VARIABLE_NAME-regular.ttf</item>
</style>
Then, in my custom TextView class i set his typeface with:
setTypeface(mFontFileName);
There is any way to face this problem? Thanks in advance.
There is any way to declare variables (using product flavors) in the build.gradle that can be substituted in the styles.xml of my Android application?
No. But you can have different versions of a styles-fonts.xml
file where you declare your typeface. Have your default in main
and override that file in other product flavors as needed. Isolate the smallest possible bit of style information into styles-fonts.xml
(or whatever you want to name it) and you can minimize redundancy between build variants.