继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

笔记 ,Android 应用_Res_ 自定义控件XML 参数

明月笑刀无情
关注TA
已关注
手记 104
粉丝 16
获赞 56

自定义参数:

步骤一:

在res/values 下, 新建styles.xml 文件,定义参数

步骤二:

在 ____View中,获取XML中传入的参数

………………

public MultiColumnListView(Context context, AttributeSet attrs, int defStyle) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MultiColumnListView); 

}

步骤三:  

 在使用 __View的地方,

 1. 声明xmlns, xlist 为自定义变量(可自定义),"http://schemas.android.com/apk/res-auto"(默认即可)

2. xRefreshMode属于自定义参数,为了能够访问得到,需要在前面加上xlist,

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

Android自定义控件的属性,在xml中使用自己自定义的attr的时候,其中有一步就是要自定义一个xml的命名空间后然后再给自定义属性赋值,现在发现不知道什么时候开始Android把这个改了,现在发现可以统一用

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

而不是原来的:

xmlns:app="http://schemas.android.com/apk/App的Package名"

还有人提到在作为lib被使用的时候,也应该用res-auto

-------------参考---------

http://blog.csdn.net/marktola/article/details/9627541

http://www.th7.cn/Program/Android/201502/393128.shtml

原文链接:http://www.apkbus.com/blog-328402-58698.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP