Android 使用XML实现按钮改变焦点设置背景图
来源:互联网 发布:矩阵相似一定合同吗 编辑:程序博客网 时间:2024/05/02 22:11
具体实现:
① 新建工程
② 准备png 背景图片defaultimage.png 、onfocusimage.png、clickimage.png
defaultimage.png onfocusimage.png clickimage.png
③ 在main.xml 布局中添加一个ImageButton 和一个Button(作对比)
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent" android:background="#FF25CCDD"><ImageButtonandroid:id="@+id/image_Button"android:layout_width="wrap_content"android:layout_height="wrap_content"<Buttonandroid:text="Button01"android:id="@+id/Button01"android:layout_width="wrap_content"android:layout_height="wrap_content"></Button></LinearLayout>
④ 在drawable 文件夹中添加一个advancedbutton.xml 设置<selector>和<item>标签
advancedbutton.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:state_focused="true"android:state_pressed="false"android:drawable="@drawable/onfocusimage"/><itemandroid:state_focused="true"android:state_pressed="true"android:drawable="@drawable/clickimage"/><itemandroid:state_focused="false"android:state_pressed="true"android:drawable="@drawable/clickimage"/><item android:drawable="@drawable/defaultimage"/></selector>
⑤ 设置ImageButton 的android:background 属性值
<ImageButtonandroid:id="@+id/image_Button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/advancedbutton"/>
⑥ 结果
- Android 使用XML实现按钮改变焦点设置背景图
- 用XML实现按钮改变焦点设置背景图
- 通过xml布局文件实现按钮改变焦点设置背景图片
- 通过xml布局文件实现按钮改变焦点设置背景图片
- js改变按钮背景图
- android使用xml实现一些常用的背景图
- android 设置textview获取焦点改变样式
- delphi使用回车设置焦点改变
- Android开发,使用背景图(xml drawable)为view 设置边框
- Android中设计具有背景图的按钮—ImageButton的焦点及事件处理
- Android中设计具有背景图的按钮—ImageButton的焦点及事件处理
- Android 点击按钮实现来回切换背景图和文字
- 通过自绘背景图改变按钮颜色
- MFC 设置焦点按钮
- Android Studio背景图设置
- android 使用xml selector设置按钮点击效果图片
- Android笔记- 使用XML selector 设置按钮点击效果图片
- Android 设置圆角按下改变颜色按钮
- NoClassDefFoundError - Eclipse添加jar包后报错
- Android的读写文件权限
- sql注入解决方法的收集
- 写一个aspx网站后的感想
- Android 轻松实现语音识别
- Android 使用XML实现按钮改变焦点设置背景图
- ORA-1157与ORA-01110错误实践
- const 指针与指向const的指针
- Android声明和使用权限
- 教你如何应对BT-HR的问题
- C#解析HTML
- Oracle BI EE 11g – Lookup Tables – Sparse and Dense Lookups
- Routing
- 关于Jquery中ajax方法data参数用法的总结