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
A style is defined in an XML resource that is separate from the XML that specifies the layout. This XML file resides under res/values/ directory of your project and will have <resources> as the root node which is mandatory for the style file. The name of the XML file is arbitrary, but it must use the . xml extension.
A style is a collection of attributes that specify the appearance for a single View . A style can specify attributes such as font color, font size, background color, and much more. A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view.
In android, the style is defined in a separate XML resource file and we can use that defined style for the Views in XML that specifies the layout. The Styles in android are similar to CSS styles in web design. Following is the example of defining a TextView control with required style attributes in an XML layout file.
Right click on res folder, choose New --> Android resource file, set the same name for the new file "styles", in Available qualifiers: choose the last item "Version" and finally set "Platform API level" 21. Show activity on this post.
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.
It depends on which Themes you're using and which context it is. These attributes are defined by different sources.
If the attribute name is prefixed with android:
, it's a framework attribute and can only be used for the Android versions having it defined.
If the attribute is not prefixed at all, the attributes are defined by your own application. This includes all attribute definitions you pulled in with libraries.
In your example you're defining a theme for AppCompat
which is part of the support library and thus of your application. The framework widgets won't recognize these colors directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With