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

Ric*_*868 6 xml android android-studio

在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>
Run Code Online (Sandbox Code Playgroud)

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

<item name="android:textColorPrimary">@color/white</item>
Run Code Online (Sandbox Code Playgroud)

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

小智 1

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

<Linear Layout
xmlns:android="http://schemas.android.com/apk/res/android">
Run Code Online (Sandbox Code Playgroud)

您需要一种方法来告诉编译器您将从该位置引用属性,并且可以使用

"android:" 
Run Code Online (Sandbox Code Playgroud)