Ric868
Ric868

Reputation: 89

use android prefix on xml (android:, app:, @.., ...)

On AndroidStudio in xml file i don't understand the difference between item with android prefix and item without it part of my source code for example:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/white</item>
    <item name="android:textColorSecondary">@color/white</item>
    <item name="actionMenuTextColor">@color/white</item>
</style>

<style name="AppTheme.toolbar" parent="Widget.AppCompat.Toolbar">
    <item name="android:background">@color/grey</item>
</style>

in this xml file why some attributes want the prefix (android:) and other not. for the example:

<item name="android:textColorPrimary">@color/white</item>

this part of code works correctly, but when the code below is used, it doesn't works: <item name="textColorPrimary">@color/white</item> So can anyone help me to know the difference between the prefix, and when i use it. thanks

Upvotes: 7

Views: 708

Answers (1)

user5154488
user5154488

Reputation:

That is because some of those attributes are from a different XML name space. In layout files, you may have seen something like:

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

You need a way to tell the compiler that you will be referencing attributes from that location, and you do that with the

"android:" 

Upvotes: 1

Related Questions