Android 自定义命名空间
- 声明规则
- 属性定义
- 示例
声明规则
一般是在布局文件的头部去声明
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:hiddenLine = "http://schemas.android.com/apk/res/com.example.hiddenline"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
一般是:http://schemas.android.com/apk/res/工程名
这样就可以在下面定义的布局文件中直接使用了.
<com.example.hiddenline.HiddenLine
android:layout_width = "match_parent"
android:layout_height = "1dp"
android:layout_marginTop = "20dp"
hiddenLine:textColor = "#f84d4d"/>
其中:textColor 是在自定义view的时候,定义的属性.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name = "hiddenline">
<attr name = "textColor" format= "color" />
</declare-styleable >
</resources>
这就是简单的实现了自定义命名空间.