自定义View的学习
来源:互联网 发布:qq三国修复数据 编辑:程序博客网 时间:2024/05/21 14:59
1、selector
a、图片资源
a.1、selector中对于图片资源的引用,使用的标签为:android:drawable
例子:对于一种图片
有两种效果,一种是有点击效果,
在drawable文件夹下建立:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/btn_content_fragment_me_click" android:state_focused="true" android:state_pressed="true"/> <item android:drawable="@drawable/btn_content_fragment_me_click" android:state_focused="true" android:state_pressed="false"/> <item android:drawable="@drawable/btn_content_fragment_me_click" android:state_focused="false" android:state_pressed="true"/> <item android:drawable="@drawable/btn_content_fragment_me"/></selector>
b、颜色资源
b.1、selector中对于颜色资源的引用,使用标签为:android:color
b.2、对于View的背景色,使用颜色资源筛选,则需要先将颜色资源转化为 drawable资源。其余和a.1一致。
在values文件夹中建立
<?xml version="1.0" encoding="utf-8"?><resources> <color name="white">#ffffff</color> <color name="red">#ff450f</color> <drawable name="drawable_white">#ffffff</drawable> <drawable name="drawable_red">#ff450f</drawable></resources>
在drawable文件夹中建立
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_focused="true" android:state_pressed="true" android:color="@color/red"/> <item android:state_focused="true" android:state_pressed="false" android:color="@color/red"/> <item android:state_focused="false" android:state_pressed="true" android:color="@color/red"/> <item android:color="@color/white"/></selector>
c、样式资源(shape)
设置TextView、Buttonde的样式
有一个神器网站http://angrytools.com/android/button/
、shape
a、圆角属性:conner
b、渐变属性/填充属性:gradient/solid
c、间隔属性:padding
d、大小属性:size
e、描边属性:stroke
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 圆角属性 --> <corners android:radius="7dp" android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp" android:topLeftRadius="2dp" android:topRightRadius="2dp" /> <!-- 渐变属性 --> <gradient android:startColor="#f7fc12" android:centerColor="#11fd11" android:endColor="#265324" android:type="radial" android:centerX="0" android:centerY="0" android:angle="45" android:gradientRadius="90" /> <!-- 间隔属性 --> <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" /> <!-- 大小属性 -->> <size android:width="100dp" android:height="100dp" /> <!-- 填充属性 --> <solid android:color="#ffffff" /> <!-- 描边属性 --> <stroke android:width="2dp" android:color="#000000" android:dashWidth="2dp" android:dashGap="2dp" /></shape>
2、style/theme
a、在style.xml中定义style标签,来封装一些控件共有的属性。
b、在控件如果出现和style中重复的属性操作,则控件中直接定义的属性标签会覆盖掉
style中的属性效果。
c、style中没有提示的标签或者值,不一定是不存在的。
d、style的继承:子style会继承父style的全部属性,如果出现覆写父style中的属性 标签,则达到覆盖效果。
例如:
<!-- TextView样式一 --> <style name="TextViewStyle"> <item name="android:textSize">20sp</item> <item name="android:textColor">@drawable/selector_textview_colors</item> <item name="android:background">#abd0bc</item> <item name="android:layout_width">60dp</item> <item name="android:layout_height">60dp</item> <item name="android:gravity">center</item> </style> <!-- TextView样式2 --> <style name="TextViewStyle2" parent="TextViewStyle"> <item name="android:background">#ab346c</item> </style>
一、Android中的所有控件(不包含布局)
TextView 文本视图 (常用)
EditText 文本编辑框 (常用)
Button 按钮 (常用)
ImageView 图像视图 (常用)
ImageButton 图像按钮 (常用)
ToggleButton 开关按钮、Switch开关
RadioButton 单选按钮 (常用)
CheckBox 多选框 (常用)
Spinner 下拉菜单 (常用)
AutoCompleteTextView 自动完成文本框 (常用)
ProgressBar 进度条 (常用)
SeekBar 拖动条
RatingBar 星级评分条
TimePicker、DatePicker 时间选择器、日期选择器
AnalogClock、DigtalClock 模拟时钟、数字时钟
Dialog 对话框
AlertDialog 提示对话框 (常用)
ProgressDialog 进度对话框 (常用)
TimePickerDialog 时间选择对话框
DatePickerDialog 日期选择对话框
ListView 列表视图(Android中最重要视图之一)
GridView 网格视图(常用)
ScrollView 滚动视图(常用)
ExpandableListView 可展开列表视图
WebView 网页视图(常用)
SerchView 搜索框
TabHost 书签选项卡
Notification 通知 (常用)
Toast 吐司 浮动提醒 (常用)
Menu 菜单(常用)
OptionMenu 选项菜单 (常用)
ContextMenu 上下文菜单 (常用)
PopuMeu 弹出菜单 (常用)
ActionBar 动作导航条
- 自定义view的学习
- 自定义View的学习
- 自定义View的框架学习
- 简单的学习自定义view
- 自定义View的学习(1)
- 自定义View的自我学习
- 自定义View的学习1
- 自定义View的学习2
- Android的绘图机制学习---自定义View
- android学习笔记-自定义View的属性
- 自己学习自定义view的一些总结
- 自定义View中关于文本的学习
- 自定义view学习-创建自己的九宫格解锁view
- 自定义View学习笔记(4)->凹凸的View
- Android学习 自定义View
- 自定义View学习
- ToggleButton自定义View学习
- 初步学习自定义view
- Android_sdk目录结构详解
- ASP.NET服务器控件的生命周期
- iPhone回滚APP的方法
- Aggregate方法
- spring in action 第3章
- 自定义View的学习
- 百度地图API(二)
- final, finally, finalize的区别
- Mybatis 通过Map传多个参数过来
- canvas
- nginx+lua_nginx+GraphicsMagick生成实时缩略图
- 文件上传所发生的一些事?
- 【逆元】
- LINQ to SQL语句之运算符转换和ADO.NET与LINQ to SQL