自定义view继承Button
来源:互联网 发布:python中执行shell脚本 编辑:程序博客网 时间:2024/05/20 16:45
//获取自定义属性
private void initAttrs(Context context, AttributeSet attrs) {
//从属性文件里获取属性集合
TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.MyCustomButton );
//获取属性
int num = typedArray.getInt(R.styleable.MyCustomButton_bttextNum, 0);
int resourceId = typedArray.getResourceId(R.styleable.MyCustomButton_btbackground, 1);
//把属性设置给自定义的控件
setText(num + "");
setBackgroundResource(resourceId);
//利用
typedArray.recycle();
private void initAttrs(Context context, AttributeSet attrs) {
//从属性文件里获取属性集合
TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.MyCustomButton );
//获取属性
int num = typedArray.getInt(R.styleable.MyCustomButton_bttextNum, 0);
int resourceId = typedArray.getResourceId(R.styleable.MyCustomButton_btbackground, 1);
//把属性设置给自定义的控件
setText(num + "");
setBackgroundResource(resourceId);
//利用
typedArray.recycle();
}
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
<resources>
<declare-styleable name="MyCustomButton">
<attr name="bttextNum" format="integer"></attr>
<attr name="btbackground" format="reference|color"></attr>
</declare-styleable>
</resources>
阅读全文
0 0
- 自定义view继承Button
- 自定义View之继承原有View 例自定义Button
- 自定义View继承view
- 自定义View---继承View
- 自定义View,继承View
- 自定义view继承view
- 自定义View button
- 自定义View和自定义Button
- 自定义view,之自定义button
- 自定义view之----自定义button
- 自定义View-继承系统View
- 自定义view之继承view
- 自定义View之 继承View
- 继承View自定义控件
- 自定义view 之 继承
- 自定义控件-继承View
- 自定义view继承surfaceview
- android自定义View-继承
- 测试
- 动态规划-试题(4)-转移罪犯
- 二分查找及插值查找
- C#基础-045 练习题
- SQL Server 触发器
- 自定义view继承Button
- jdbc 增删改的通用方法
- 安装配置office
- MYSQL千万级数据量的优化方法积累
- idea安装以及初始化
- notepad++
- 常用排序之冒泡排序法
- 我的CSDN博客起点
- linux下软件卸载