Search code examples
androidstylesandroid-theme

Why and when we need to add android: prefix to style?


I have seen that some Style attributes require android prefix and some don't need it. What is the reason. like

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Why we haven't use android:windowActionBar and android:windowNoTitle


Solution

  • Based on SDK version Android styles are grouped in different namespaces. In order to override a Theme you have to follow it's namespace.

    That's the reason you don't need the android: prefix when extending an AppCompat Theme, but if you wanted something else, let's say Theme.Holo - you'd have 2 different styles for the them - one for pre-Lollipop devices, and one for -21, the latter having the android: prefix before each style attribute.