Button和ImageButton的使用
来源:互联网 发布:mysql自增identity 编辑:程序博客网 时间:2024/05/17 04:52
本人平时做项目时,这两个控件使用的较少,一般都用TextView代替,这里重新学习下他们的用法。
参考文章 :http://www.runoob.com/w3cnote/android-tutorial-button-imagebutton.html
1.点击变色效果
StateListDrawable是Drawable资源的一种,可以根据不同的状态,设置不同的图片效果,关键节点 < selecotr >,我们只需要讲Button的blackground属性设置为该drawable资源即可轻松实现,按下 按钮时不同的按钮颜色或背景!
我们可以设置的属性:
drawable:引用的Drawable位图,我们可以把他放到最前面,就表示组件的正常状态~
state_focused:是否获得焦点
state_window_focused:是否获得窗口焦点
state_enabled:控件是否可用
state_checkable:控件可否被勾选,eg:checkbox
state_checked:控件是否被勾选
state_selected:控件是否被选择,针对有滚轮的情况
state_pressed:控件是否被按下
state_active:控件是否处于活动状态,eg:slidingTab
state_single:控件包含多个子控件时,确定是否只显示一个子控件
state_first:控件包含多个子控件时,确定第一个子控件是否处于显示状态
state_middle:控件包含多个子控件时,确定中间一个子控件是否处于显示状态
state_last:控件包含多个子控件时,确定最后一个子控件是否处于显示状态
代码实现:
1)先准备两种不同颜色的背景,这里也用drawable实现,用图片也行。
按下后的背景 文件名: round_stroke_shape_background.xml<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dp" /> <solid android:color="#0dbfc6"/></shape>
默认的背景 文件名:round_stroke_shape_background_default.xml<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="5dp" /> <solid android:color="#ffffff"/></shape>
2)用StateListDrawable资源设置按下效果
文件名:myselect.xml<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@drawable/round_stroke_shape_background"></item> <item android:state_enabled="false" android:drawable="@drawable/round_stroke_shape_background_default"></item> <item android:drawable="@drawable/round_stroke_shape_background_default"></item></selector>
3)将myselect.xml设置为Button的背景
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@drawable/myselect" android:padding="15dp" android:text="点我变色" android:textSize="16sp" />
效果图如下:
2.按钮按下的波纹效果
待续,直接给demo
http://download.csdn.net/detail/kinglong68/9468962 eclipse
http://download.csdn.net/detail/kinglong68/9468950 studio
- Button和ImageButton的使用
- Button的使用(十):ImageButton
- button以及Imagebutton的使用
- imageButton 和button的区别
- android ImageButton与Button的使用
- button和imagebutton控件的区别
- button和imagebutton控件的区别
- button和imagebutton控件的区别 .
- Android ImageButton和Button的区别
- android ImageButton 和Button的图标区别
- ToggleButton Button ImageButton 的区别和用法
- Button和ImageButton的背景选择
- Button和ImageButton的监听事件
- Button和ImageButton基础
- Button和ImageButton
- Button和ImageButton控件
- Android-Button和ImageButton
- Android-Button和ImageButton
- 部署var包至远程服务器
- NYOj-236-心急的C小加
- Python 从文件中匹配字符串
- 关于微信支付
- 【杭电oj】1334 - Perfect Cubes(水)
- Button和ImageButton的使用
- LVS+keepalived
- 220. Contains Duplicate III
- flume-ng version 报找不到org.apache.flume.tools.GetJavaProperty
- 架构师
- redis spring 集成
- ajax的原理和运行机制
- OC获取文件MD5值与swift字符串MD5加密方法
- IIS7 请求筛选模块被配置为拒绝超过请求内容长度的请求