Android高手秘笈之自定义View的属性
16lz
2021-01-26
1. 自定义控件属性使用步骤
- 1.1 在attrs.xml中定义控件属性
<?xml version="1.0" encoding="utf-8"?>
- 1.2 在调用的xml文件指定命名空间
a.系统默认的命名控件
xmlns:android="http://schemas.android.com/apk/res/android"
b.自定义控件的命名写法1【自动查找】
xmlns:app="http://schemas.android.com/apk/res-auto"
c.自定义控件的命名写法2
xmlns:app="http://schemas.android.com/apk/res/app的包名字" 【明确所在的包查找】
- 1.3 调用自定义控件
- 1.4 获取自定义控件的属性值
public AttrView(Context context,AttributeSet attrs,int defStyleAttr){TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AttrView);int value = typedArray.getInt(R.styleable.AttrView_test1,0);}
更多相关文章
- 关于selector点击区域放大问题的解决
- Android(安卓)AndroidManifest.xml 结构详解
- android Installation error: INSTALL_FAILED_CONFLICTING_PROVI
- Android(安卓)Selector用法小记
- 模仿墨迹天气设置界面布局
- Android中getResources().getDrawable() 过时问题分析
- WindowManager实现悬浮窗口
- LinearLayout布局中如何让控件置底
- android style用法