在android中使用自定义属性和命名空间
包结构基本上是:在android中使用自定义属性和命名空间,android,namespaces,Android,Namespaces,包结构基本上是:app>src>main>com.example.CustomView,其中存在一个view文件夹,其中包含CustomView.java文件 在res文件夹中的attrs.xml文件中,我定义了一个stylable,如下所示: <resources> <declare-styleable name="PieChart"> <attr name="showText" format="boolean"/> <
app>src>main>com.example.CustomView
,其中存在一个view
文件夹,其中包含CustomView.java
文件
在res
文件夹中的attrs.xml
文件中,我定义了一个stylable
,如下所示:
<resources>
<declare-styleable name="PieChart">
<attr name="showText" format="boolean"/>
<attr name="labelPosition" format="enum">
<enum name="left" value="0"/>
<enum name="right" value="1"/>
</attr>
</declare-styleable>
</resources>
但是对于定义的名称空间,android在编辑器中给了我以下错误消息:
在Gradle项目中,始终用于自定义属性较少。。。(Ctrl+F1)检验信息:在Gradle项目中,最终APK中使用的实际包装可能会有所不同;例如,您可以在一个版本而不是另一个版本中添加.debug包后缀。因此,您不应该在资源中硬编码应用程序包;相反,使用特殊的名称空间,这将导致工具为资源找出正确的名称空间,而不考虑在构建期间使用的实际包 这就带来了以下两个问题:
http://schemas.android.com/apk/res-auto
do,is
它是由android动态解析的吗?就像app
名称空间一样
解析为一个URI,并用于自定义命名空间
另一个
您不应该需要自定义名称空间。如果您的customviews软件包包含在您的项目中,它的属性将合并到您的项目中,您只需使用app:for-them即可。Hm。。。。但是为什么android doc会使用它和。。。。当我们使用
时,“使工具找出正确的名称空间”这句话是什么意思http://schemas.android.com/apk/res-auto“
名称空间?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res/com.example.customviews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:gravity="center">
...
...
...
</LinearLayout>