Android – What does the AppBaseTheme do in android apps

androidandroid-theme

I am unable to understand what happens with AppBaseTheme in Android.
In styles.xml I have the following code

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="mycolor">
    <item name="android:background">@layout/header_gradient</item>
    <item name="android:padding">5dip</item>
</style>
<style name="myParentTheme" parent="android:Theme.Light">
    <item name="android:attr/windowTitleSize">40dip</item>
    <item name="android:attr/windowTitleBackgroundStyle">@style/mycolor</item>
</style>


<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>

In AndroidManifest.xml when I use android:theme="@style/myParentTheme" the color and size of the title are set to what I want to set. But the style for text fields changes to the old regular textboxes. When I use android:theme="@style/AppTheme" the UI looks very "Android-like" but my specific settings to the title do not have any effect. Removing parent="AppBaseTheme" makes the AppTheme style behave just like the myParentTheme style.

Additionally, why do I not see all R.attr elements when I do Ctrl+Space while typing in the name attribute of the Style tag?

Please help. Thanks.

Best Answer

If you choose to create an activity using the Eclipse new-project wizard, Eclipse will define AppTheme and AppBaseTheme resources for you. AppBaseTheme typically will have three definitions, in res/values/, res/values-v11/, and res/values-v14/. AppTheme will inherit from AppBaseTheme.

The intent is for you to put most of your app-specific style information in AppTheme, rather than inventing your own theme (e.g., myParentTheme). AppBaseTheme would mostly ensure that you are inheriting from the right OS-supplied theme (e.g., Theme.Light vs. Theme.Holo.Light vs. Theme.Holo.Light.DarkActionBar). You can also add version-specific style information to the appropriate AppBaseTheme if you wish.

In AndroidManifest.xml when I use android:theme="@style/myParentTheme" the color and size of the title are set to what I want to set. But the style for text fields changes to the old regular textboxes.

That is because you are inheriting from Theme.Light, which uses the original (non-holographic) widget set.

When I use android:theme="@style/AppTheme" the UI looks very "Android-like" but my specific settings to the title do not have any effect.

That is because you decided to create myParentTheme instead of putting your style definitions into AppTheme.