Android 自定义控件
来源:互联网 发布:排序算法总结 编辑:程序博客网 时间:2024/05/01 02:38
自定义控件配置新增属性几步骤
1. 在values文件夹下声明属性
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="navigation">
<attr name="btn_leftText" format="string"/>
<attr name="btn_rightText" format="string"/>
<attr name="btn_drawable" format="reference"/> 定义引用资源
</declare-styleable>
</resources>
2. 在引用自定义控件需要用属性必须声明空间
xmlns:navigation="http://schemas.android.com/apk/res/com.example.mynavigation(自定义类的包名)"
3. 获取属性值(在自定义类的构造方法中通过 AttributeSet获取)
public MyNavigation(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray=context.obtainStyledAttributes(attrs, R.styleable.navigation);
Log.e("zhouyou", typedArray.getText(R.styleable.navigation_btn_leftText)+"");
Log.e("zhouyou", typedArray.getText(R.styleable.navigation_btn_rightText)+"");
typedArray.recycle();
}
1. 在values文件夹下声明属性
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="navigation">
<attr name="btn_leftText" format="string"/>
<attr name="btn_rightText" format="string"/>
<attr name="btn_drawable" format="reference"/> 定义引用资源
</declare-styleable>
</resources>
2. 在引用自定义控件需要用属性必须声明空间
xmlns:navigation="http://schemas.android.com/apk/res/com.example.mynavigation(自定义类的包名)"
3. 获取属性值(在自定义类的构造方法中通过 AttributeSet获取)
public MyNavigation(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray=context.obtainStyledAttributes(attrs, R.styleable.navigation);
Log.e("zhouyou", typedArray.getText(R.styleable.navigation_btn_leftText)+"");
Log.e("zhouyou", typedArray.getText(R.styleable.navigation_btn_rightText)+"");
typedArray.recycle();
}
0 0
- [Android自定义控件] Android自定义控件
- Android自定义控件] Android自定义控件
- [Android自定义控件] Android自定义控件
- [Android自定义控件] Android自定义控件
- [Android自定义控件] Android自定义控件
- [Android自定义控件] Android自定义控件
- [Android自定义控件] Android自定义控件
- Android 自定义控件 单页翻书控件
- android虚线控件---自定义控件
- android自定义控件实例 --控件
- Android自定义控件--组合控件
- android 控件 自定义组合控件
- 【android自定义控件】ProgressBar自定义
- Android自定义控件 自定义属性
- Android自定义控件 -- 自定义View
- Android自定义控件 -- 自定义ViewGroup
- Android 自定义控件 自定义标题栏
- Android 自定义控件-自定义进度条。
- GDB 调试总结
- MyBatis之插件MyBatisLink
- GTK - 实现MessageBox -- 图形界面--跨平台
- 二维数组参数与二维指针参数
- leetcode-78 Subsets
- Android 自定义控件
- Android Activity之间跳转与传值
- Testlink1.9.7和Jira的集成
- Java中Clone方法的浅复制和深复制
- java后端系统架构之技术架构验证篇1
- Ubuntu-10.10如何给用户添加sudo权限
- JDBC基础知识(备忘)
- 单例模式
- Android四大基本组件介绍与生命周期