Wednesday, April 23, 2014

Android:Best practices to use default them.

Android Default Them:

Android allows you to set the appearance of your application using themes.A theme specifies default colors, fonts, and images, for an Android activity or an entire application. Your application can use the device's built-in themes, or include custom themes. By default, Titanium applications use a custom theme called Titanium for their main activity.

If you try to use an unsupported theme, you will either receive a build error that
the resource cannot be found or a runtime error that the theme is not supported.

At First, create a theme XML file in ./platform/android/res/values. Do NOT name the file theme.xml. . 
If you create a file called theme.xml, it will overwrite the default Titanium one and break the build process.
//platform/android/res/values/builtin_themes.xml
<!-- Works for Titanium SDK 3.2.x and earlier when built against Android 4.0x/API Level 14 -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
      <!-- Available for Android 4.0.x/API Level 14 and later -->
      <style name="LightDarkBar" parent="@android:style/Theme.Holo.Light.DarkActionBar"/>
      <!-- Available for Android 3.0.x/API Level 11 and later -->
      <style name="Light" parent="@android:style/Theme.Holo.Light"/>
      <style name="Dark" parent="@android:style/Theme.Holo"/>
      <!-- Available for all Android versions -->
      <style name="OldLight" parent="@android:style/Theme.Light"/>
      <style name="OldDark" parent="@android:style/Theme.Black"/>
</resources>


Finally, to use a theme in your application, modify the Android section of your tiapp.xml file to reference the style name you want to use

<android xmlns:android="http://schemas.android.com/apk/res/android">
       <manifest>
             <application android:theme="@style/LightDarkBar"/>
             <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/>
        </manifest>
</android>

For more details:Android Theme

No comments:

Post a Comment