【问题标题】:app:something...What is app:?应用程序:某事...什么是应用程序:?
【发布时间】:2015-01-05 12:21:37
【问题描述】:

我在我的项目中使用this famous ViewPagerIndicator library。我想在ViewPageIndicator 上添加颜色。我从here on StackOverflow 找到了解决方案。

<com.viewpagerindicator.CirclePageIndicator
    android:id="@+id/indicator"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    app:fillColor="#FF888888"
    app:pageColor="#88FF0000"
    app:strokeColor="#FF000000" />

但有一点我在这里无法理解:为什么写成app: 而不是android:app: 是什么意思?我从未使用过app:?它的命名空间是什么?我用谷歌搜索但没有找到解决方案。

【问题讨论】:

标签: android xml android-layout android-viewpager viewpagerindicator


【解决方案1】:

对于命名空间,添加:xmlns:app="http://schemas.android.com/apk/res-auto" 应用命名空间用于所有“新”属性。例如:如果我制作了一个自定义视图,它有自己的属性(比如说 RainbowView 具有新的属性“numberOfColors”),那么我必须在 app 命名空间中使用该属性,因为它没有在 android 命名空间中声明。因此,为所有自定义属性使用 app 命名空间。您定义自己的 attrs,或添加的库的作者(在您的情况下为 CirclePageIndicator)。但大多数情况下,当您开始输入“strokeCo...”并在自动完成列表中看到“strokeColor”时,命名空间会在您选择时自动添加。

【讨论】:

    【解决方案2】:

    可能你只需要添加缺少的命名空间:

    xmlns:app="http://schemas.android.com/apk/res-auto"
    

    或者看看这个引用库的答案:

    How can I set up custom namespaces in layout file in Android studio?

    【讨论】:

      猜你喜欢
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 2018-09-01
      • 2019-06-19
      • 2010-11-08
      相关资源
      最近更新 更多