在res/values下创建attrs.xml
来源:互联网 发布:debian软件安装位置 编辑:程序博客网 时间:2024/05/22 06:01
1.在res/values下创建attrs.xml
<declare-styleable name="MyRadioButton"> <attr name="str" format="string"/> </declare-styleable>
MyRadioButton为组件名字,随意起,attr标签定义组件的属性,name对应的是属性名,format是属性的类型,具体可参见《[Android]attrs.xml文件中属性类型format值的格式》。
2.在自定义的组件中使用attrs.xml文件的定义
public class MyRadioButton extends RadioButton { private String url; public MyRadioButton(Context context, AttributeSet attrs) { super(context, attrs); TypedArray taArray = context.obtainStyledAttributes(attrs,R.styleable.MyRadioButton); this.url = taArray.getString(R.styleable.MyRadioButton_str); taArray.recycle(); } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } }
a. TypedArray是存放资源R.styleable.MyRadioButton指定的属性集合。
b. 通过getXXX()获取属性值。
c. recycle()结束绑定
3.在布局文件中使用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:demo="http://schemas.android.com/apk/res/net.csdn.blog.wxg630815" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content" > <net.csdn.blog.wxg630815.MyRadioButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/myradio1" demo:str="1.csdn.net" /> <net.csdn.blog.wxg630815.MyRadioButton android:layout_width="fill_parent" android:layout_height="wrap_parent" android:id="@+id/myradio2" demo:str="2.csdn.net" /> </RadioGroup> </LinearLayout>
0 0
- 在res/values下创建attrs.xml
- android 自定义属性的使用一、在res/values文件下定义一个attrs.xml文件,代码如下
- Android中自定义属性的使用------res/values文件下定义一个attrs.xml
- Android中自定义属性的使用------res/values文件下定义一个attrs.xml
- Android 实现添加本地数组在Res/values下的xml文件
- Andriod res\values\strings.xml
- 笔记32--目录values下xml文件:TypeArray、attrs、styles、colors、strings、dimens
- 目录values下xml文件:TypeArray、attrs、styles、colors、strings、dimens
- 自定义TextView,在values下面新建attrs.xml,布局,重写方法
- 在res/values中的文件
- 在res/values中的文件
- res/values目录常用xml文件
- 在android工程中,res目录下又有anim、drawable、layout、menu、raw、values和xml文件夹,分别用来保存?
- res资源文件学习之res/values/attr.xml
- Android反编译apk得到的res中values目录下的public.xml文件的作用
- res/values-11/styles.xml与res/values-14/styles.xml 报错解决
- 创建helloWorld app,报错workspace\appcompat_v7\res\values-v21\styles_base.xml No resource found that matc
- 升级android sdk到5.0,创建项目类似错误:appcompat_v7\res\values-v21 \themes_base.xml:191: error: Error: No resour
- Android Studio 集成SVN 整理
- java finalize()方法
- Intersection of Two Linked Lists
- Android得到Layout里的布局文件里的自定义组件
- python装饰器计算函数运行时间
- 在res/values下创建attrs.xml
- 解决win8系统下subst使用不正常的问题
- 【笔记】软件活动中的浪费
- 民族 sql
- shell 字符串截取
- 二叉树非递归
- 性能优化笔记
- Python logging官方文档链接
- Android Viewpager实现图片轮播(仿优酷效果)