Skip to content

Instantly share code, notes, and snippets.

@smyykb
Created January 30, 2018 17:34
Show Gist options
  • Save smyykb/b4b4078f6f236ad3278bdd5c605c0122 to your computer and use it in GitHub Desktop.
Save smyykb/b4b4078f6f236ad3278bdd5c605c0122 to your computer and use it in GitHub Desktop.
Custom attributes in styles.xml
<Button
android:layout_width="wrap_content"
android:layout_height="?attr/defaultButtonHeight"
android:text="Button"
android:textColor="?attr/defaultButtonColor"
/>
<resources>
...
<attr name="defaultButtonColor" format="reference" />
<attr name="defaultButtonHeight" format="reference"/>
</resources>
<resources>
...
<color name="red">#f00</color>
</resources>
<resources>
...
<dimen name="dp_100">100dp</dimen>
</resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="defaultButtonColor">@color/red</item>
<item name="defaultButtonHeight">@dimen/dp_100</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment