What you learn: You will learn how to apply a Theme to your Application using not more than I line of Code in XML or JAVA.
Difficulty: 0.5 of 5
What it will look like: [align=center]Example-Themes on my Android FileBrowser -Tutorial. Default vs. Black Theme.
[/align]
Description:
If you do not explicitly specify a theme for your UI, Android will use the default theme defined by android.R.style.Theme. Many times you will want to use a different system theme (such as Theme.Dark) or create your own theme (as described in Style and Theme Resources).
[align=center]... the XML-Way.[/align]
To set your theme in XML, simply specify the desired theme in your AndroidManifest.xml file with the theme attribute. This can be used with the <application> tag (shown here) to specify a default theme for all of your activities, and/or with the <activity> to control the theme of a particular activity.
Using xml Syntax Highlighting
- <!-- AndroidManifest.xml-->
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.google.android.home">
- <application android:theme="@android:style/Theme.Dark" >
- <activity class=".Home"
- ...
- </activity>
- </application>
- </manifest>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
[align=center]... and the JAVA-Way.[/align]
You can also set the theme programmatically, if needed. When doing so, be sure to set the theme before creating any views so that the correct theme is used for all of your user-interface elements. Note that this approach should typically be avoided, especially from the main activities of your application, because the theme you set here may not be used for any animations the system uses to show the activity (which is done before your application starts).
Using java Syntax Highlighting
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- // ...
- // Call setTheme before creation of any(!) View.
- setTheme(android.R.style.Theme_Dark);
- // ...
- setContentView(R.layout.main);
- }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
[align=center]Thats it
[/align]
Regards,
plusminus







