在xml上使用android前缀(android:,app:,@ ..,…)

前端之家收集整理的这篇文章主要介绍了在xml上使用android前缀(android:,app:,@ ..,…)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在xml文件中的 AndroidStudio上,我不明白带有android前缀的项目与没有它的项目之间的区别
我的源代码的一部分,例如:

<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>

在这个xml文件中为什么有些属性需要前缀(android :)等等.
例如:

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

这部分代码可以正常工作,但是当使用下面的代码时,它不起作用:
    < item name =“textColorPrimary”> @ color / white< / item>
所以任何人都可以帮助我知道前缀之间的区别,以及何时使用它.谢谢

解决方法

这是因为其中一些属性来自不同的XML名称空间.
在布局文件中,您可能已经看到过类似的内容

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

您需要一种方法告诉编译器您将引用该位置的属性,并使用

"android:"

猜你在找的XML相关文章