1.定义attrs.xml

<?xml version="1.0" encoding="utf-8"?>                                                        

2.xml中使用自定义属性

<?xml version="1.0" encoding="utf-8"?>        

3.命名规则

方式一:

    命名空间写法:xmlns:空间名="http://schemas.android.com/apk/res/自定义组件所在包名" 

             空间名随便定义,引用时保持一致,如myandroid

方式二:

    命名空间写法:xmlns:空间名="http://schemas.android.com/apk/res-auto" 

             空间名随便定义,引用时保持一致,如myandroid

    区别:

Issue 9656: Library projects don't support custom XML attributes for custom classes

Solution:

Upgrade to latest SDK & ADT version (fixed was released since r17) and usehttp://schemas.android.com/apk/res-auto as custom attributes' namespace URI, see Revisions for ADT 17.0.0:

Added support for custom views with custom attributes in libraries. Layouts using custom attributes must use the namespace URI http://schemas.android.com/apk/res-auto instead of the URI that includes the app package name. This URI is replaced with the app specific one at build time.

如果你当前工程是做为lib使用,那么你如上所写 ,会出现找不到自定义属性的错误 ,这时需要使用"http://schemas.android.com/apk/res-auto



更多相关文章

  1. Android中使用自定义的字体
  2. android自定义控件打包成jar文件
  3. 自定义View组件
  4. 【起航计划 005】2015 起航计划 Android(安卓)APIDemo的魔鬼步伐
  5. eventloop(ril.cpp)函数中定义的管道的作用(Android)
  6. arcgis for android 学习 - (8) 空间查询 - 点击某点,选中该点所
  7. Android(安卓)自定义实现日历控件
  8. Android进阶之数据存储+Preferences
  9. Android8.0中获取U盘的各种信息

随机推荐

  1. Android(安卓)长按识别图中二维码
  2. “android studio 运行程序提示Applicati
  3. android中textview设置为多行文本时,如何
  4. Android(安卓)Initialization Process --
  5. Android(安卓)Wear Preview- 创建通知(Cre
  6. 2013.12.03 ——— android onPrepareOpt
  7. android 正则表达式
  8. Android中的BinderProxy.finalize()或Pla
  9. android 开源项目推荐
  10. android 悬浮窗口