Skip to content

Instantly share code, notes, and snippets.

@saurabharora90
Last active February 17, 2018 12:35
Show Gist options
  • Save saurabharora90/f6e0825cb2204fe7ec0029322969f533 to your computer and use it in GitHub Desktop.
Save saurabharora90/f6e0825cb2204fe7ec0029322969f533 to your computer and use it in GitHub Desktop.
Primer on Styles and Themes
<!-- A theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/randomRed</item>
<item name="alertDialogTheme">@style/MyDialog</item>
</style>
<style name="MyDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="colorAccent">@color/secondary</item>
</style>
<!-- Style -->
<style name="MyStyle">
<item name="android:background">@color/red</item>
<item name="android:alpha">0.5</item>
<item name="android:maxLines">2</item>
</style>
<!--Apply a theme inside manifest-->
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme"/>
<!-- Apply a style on a view-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
style="@style/MyStyle" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment