How To Apply Theme In Android

Theme: Is a collection of one or more styles (as defined in the resources) but instead of applying the style to a specific control, the style is applied to all View objects within a specified Activity.

 

Applying a theme to a set of View objects all at once simplifies making the user interface look consistent.
An Android theme is essentially a style that is applied to an entire screen. You can specify the theme programmatically by calling the Activity method setTheme() with the style resource identifier.
Specify the theme programmatically by calling the Activity method setTheme() with the style resource identifier.
Styles and attributes defined in the layout files explicitly override those in the theme.
<style name=”right”>
<item name=”android:gravity”>right</item>
</style>
Apply this as a theme to the whole screen, which causes any view displayed within that Activity to have its gravity attribute to be right-justified.
Applying this theme :
setTheme(R.style.right);
You can also apply themes to specific Activity instances by specifying them as an attribute within the <activity> element in the AndroidManifest.xml file, as follows:
<activity android:name=”.myactivityname”
android:label=”@string/app_name”
android:theme=”@style/myAppIsStyling”>
Multiple themes can be applied to a screen.
setTheme(R.style.right);
setTheme(R.style.green_glow);
Apply all themes before calling the method setContentView() or the inflate() method so that the themes’ attributes can take effect.
Android comes with a number of built-in themes that can be a good starting point.These include such themes as Theme_Black, Theme_Light, and Theme_NoTitleBar_Fullscreen, as defined in the android.R.style class.

 

0 comments:

Post a Comment

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | Grocery Coupons