Skip to content

Instantly share code, notes, and snippets.

@alunsford3
Last active September 21, 2017 17:36
Show Gist options
  • Save alunsford3/3c3ea265fa4ff06d15b31b72d58318a3 to your computer and use it in GitHub Desktop.
Save alunsford3/3c3ea265fa4ff06d15b31b72d58318a3 to your computer and use it in GitHub Desktop.

If the app has the ability to switch between different app color themes, every view must use a style or refer to a custom ?attr/ for all colors.

attrs.xml has:

<attr name="subtitle_1_color" format="color"/>

Which is mapped in styles.xml:

<style name="AppTheme.Dark">
	<item name="subtitle_1_color">@color/white</item>
</style>

<style name="AppTheme.Light">
	<item name="subtitle_1_color">@color/dark_gray</item>
</style>

<style name="Subtitle_1">
	<item name="text_color">?attr/subtitle_1_color</item>
	<item name="text_size">@dimen/subtitle_1_text_size</item>
</style>

Usage in layout:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/tos_accept_button_title"
    style="@style/Subtitle_1"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment