android随笔13——自定义属性
2015-12-26 16:07
435 查看
自定义属性的步骤:
一:声明属性
在valus中创建xml文件 attrs.xml 内容参数系统的attrs.xm-- 声明一个属性集合,名称可以随意,一般和拥有这些属性的类,同名 -- "<" declare-styleable name="SettingItemView" ">" -- 声明一个属性名称可以随意,类型是字符串类型 -- "<" attr name="sv_title" format="string" / ">" -- 声明一个属性名称可以随意,类型是字符串类型 -- "<" attr name="sv_descs" format="string" / ">" "<"/declare-styleable">" "<"/resources">"
二:在布局中使用属性
1- 声明命名空间:
xmlns:itcast="http://schemas.android.com/apk/res/zz.itcast.mobileguardz10" <span style="color:#ff0000;">xmlns xml name space itcast 是命名空间的缩写 将最后一个android 改为当前应用的包名</span>
<span style="color: rgb(51, 51, 51); font-family: 'Microsoft Yahei', Simsun; font-size: 24px; line-height: 38px;">2- 使用属性</span>
android:id="@+id/sv_auto_update" android:layout_width="match_parent" itcast:sv_title = "自动更新设置" itcast:sv_descs = "自动更新已经开启#自动更新没有开启" android:layout_height="wrap_content" android:background="@drawable/grid_item_bg" />
三:在代码中获得属性的中值
相关文章推荐
- Android 代码设置来电铃声
- Android Context完全解析,你所不知道的Context的各种细节
- android inflater 用法
- Android开启多进程
- android system.exit(0)后会重启
- Android编程开发实现带进度条和百分比的多线程下载
- 如何在android studio中配置lib
- Android使用SharedPreferences保存数组
- Android 正确修改项目包名而不报错的方法...
- Android中自定义SeekBar的背景颜色,进度条颜色,以及滑块的图片
- Android greenDao 使用教程(一)源码编译与使用
- android:windowSoftInputMode属性详解
- 【风马一族_Android】android的新发现
- 学习笔记1: Activity 生命周期
- Android之获取手机上已安装的所有的应用程序的信息,并判断是否安装了某应用程序(系统程序或非系统应用程序判断)
- android——fragment长时间home或者锁屏java.lang.IllegalArgumentException:No view found for id for....
- android——拍照,相册图片剪切其实就这么简单
- android——生成或者下载的图片在相册中找不到
- android——fragment详解
- Android:弄明白Touch事件分发机制