STYLES A resource that defines format and look for a UI. Can be applied to individual entities or to activities as a whole. It is a .XML file.
Defining Styles The XML file resides under res/values/ directory of your project and will have <resources> as the root node which is mandatory for the style file. <style> tag is used to define a style. Each style is uniquely identified by it’s name. Style attributes can be set using the <item> tag.
Sample code to create a style <resources> < stylename =" GreenText"parent =" TextAppearance.AppCompat ”> <item name=" android:textColor ">#00FF00</item> </style> </resources>
Extending a Style To create your own style, you should always extend it from the framework or support library. This is to maintain compatibility with platform UI styles. Use the ‘parent’ attribute to extend a style. You can also inherit styles by extending a style's name with a dot notation, instead of using the parent attribute.
THEME A theme is similar to style, but it is applied to a layout or an activity as a whole. It is applied to child views of each component as well. Use the android:theme attribute on either the <application>tag or an <activity> tag in the AndroidManifest.xml file.
Customizing the Default Theme By default the theme is defined in the styles.xml file. You may change this as per your desire. The colors may be changed from the colors.xml file under res/values/ colors.xml .
STYLE HIERARCHY While styling an app, you must be mindful of Android’s style hierarchy. Use themes in general, for consistency. If you've specified the same attributes in multiple places, the list below determines which attributes are ultimately applied.
STYLE HIERARCHY Applying character- or paragraph-level styling via text spans to TextView -derived classes Applying attributes programmatically Applying individual attributes directly to a View Applying a style to a View Default styling Applying a theme to a collection of Views, an activity, or your entire app Applying certain View-specific styling, such as setting a TextAppearance on a TextView