I have the following theme in res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="@android:style/Theme.NoTitleBar">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
If I remove the <item name="android:windowNoTitle">true</item> line, my activities have the titlebar on them. However, if I keep that line there, then they do not have a titlebar (which is what I want).
I’m curious why parent="@android:style/Theme.NoTitleBar" seems to have no effect? Does parent not do what I think it does? I thought it worked like this:
@android:style/Theme.NoTitleBar --> AppBaseTheme --> AppTheme
^ ^ ^
| | |
| | Has everything AppBaseTheme
| | does, unless it's overridden
| |
| Has everything @android:style/Theme.NoTitleBar
| does, unless it's overridden (which I'm not
| doing)
|
Sets whatever it needs to to not have a title, which I assume
is done by setting <item name="android:windowNoTitle">true</item>
However, I’ve also found that if I set <item name="android:windowNoTitle">true</item> in AppBaseTheme it also has no effect; I have to set it in AppTheme. Then what the heck is the point of specifying the parent?
I think I just figured it out. It turns out that when I created the project, Android created a
res/values-14/styles.xmlfile, and inside of that was<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">.It turns out that the
res/values-14/styles.xmlfile was overriding my defaultres/values/styles.xmlbecause the device I was testing on has API level 14, and thus it preferred the files invalues-14than the defaultvalues.Inheritance does seem to work like I thought it did; I just wasn’t realizing things were being overridden by the files created when I first made my project.