引用library之——带有自定义属性的自定义控件的library包

一般来讲,当自定义一个控件Panel并且此控件有自定义属性时(例如:panel:closedHandle="@drawable/foot_bar_right"),xml中需要定义此控件的引用地址,(例如:xmlns:panel="http://schemas.android.com/apk/com.example.view")

这样就可以在xml中引用自定义控件了。

复制代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
//Panel所在的包名
    xmlns:panel="http://schemas.android.com/apk/com.example.view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
//自定义控件Panel
    <com.example.view.Panel
        android:id="@+id/panel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="left"
        panel:closedHandle="@drawable/foot_bar_right"
        panel:content="@+id/panelContent"
        panel:handle="@+id/panelHandle"
        panel:openedHandle="@drawable/foot_bar_left"
        panel:position="left" >
    </com.example.view.Panel>
复制代码

但是

当想要引用的自定义控件为library时,并且此控件也具有自定义的属性,如上(它在attrs.xml中有自定义属性),此时在新项目中引用时,就不能在xml中引用包名。

而是引用:xmlns:panel="http://schemas.android.com/apk/res-auto"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android"
<span style= "color: #339966;" > //Panel所在的包名</span>
     <span style= "color: #ff6600;" >xmlns:panel= "http://schemas.android.com/apk/res-auto</span>"
     android:layout_width= "match_parent"
     android:layout_height= "match_parent"  >
<span style= "color: #339966;" > //自定义控件Panel</span>
     <com.example.view.Panel
         android:id= "@+id/panel"
         android:layout_width= "fill_parent"
         android:layout_height= "wrap_content"
         android:layout_alignParentBottom= "true"
         android:layout_gravity= "left"
         panel:closedHandle= "@drawable/foot_bar_right"
         panel:content= "@+id/panelContent"
         panel:handle= "@+id/panelHandle"
         panel:openedHandle= "@drawable/foot_bar_left"
         panel:position= "left"  >
     </com.example.view.Panel>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值