Android学习笔记---ImageButton
来源:互联网 发布:淘宝上lol皮肤是真的吗 编辑:程序博客网 时间:2024/04/28 11:39
ImageButton
- 用图片显示一个可以被用户按下和单击的按钮。默认情况下,ImageButton看起来和一般的Button没有什么区别。标准的Button将会在状态变化的时候,显示不同的背景颜色。ImageButton表面显示的图片通过XML属性 "android:src"来定义,或者通过setImageResource(int)方法来设置。
- 想要去除标准按钮的背景图片,可以通过定义自己的背景图片,或者设置背景为透明。
- 如果想要在按钮的不同状态下显示不同的照片,可以通过定义文件"selector.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/button_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/button_focused" /> <!-- focused --> <item android:drawable="@drawable/button_normal" /> <!-- default --> </selector>
- 将这个XML文件保存在你的/res/drawable文件夹下面。程序编译以后,可以通过引用普通的图片资源一样,引用这个XML文件。在你的ImageButton的"android:src"属性中设置后,Android系统会自动按照selector.xml文件中定义的不同图片,在按钮的不同状态下切换图片。
- 这三种不同状态的图片设置顺序很重要。因为是按照顺序来挨个判断当前状态应该使用哪一个文件。看上面的例子,普通状态是出于最后的。因为一个按钮的正常状态是在这个按钮的前两个状态都不符合的时候的一种状态。
以下是一个例子:
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"><TextView android:layout_width="fill_parent"android:layout_height="wrap_content" android:text="@string/hello" /><ImageButton android:src="@drawable/selector"android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageButton></LinearLayout>
- Android学习笔记---ImageButton
- Android学习笔记之ImageButton
- android学习笔记27--------------ImageButton
- Android学习笔记之ImageButton
- Android学习笔记--自定义ImageButton
- Android学习笔记十:基本视图组件:ImageView和ImageButton
- Android学习笔记---第三天---基础UI组件---Button&ImageButton
- android笔记3-button,imageButton
- Android开发学习笔记(六)Android应用界面编程 Button/ImageButton学习
- Android学习(六)ImageButton学习
- 安卓学习笔记(一)Android ImageButton、ImageView控件属性设置 图片显示问题
- android 学习 ---控件按钮,Button 与ImageButton,
- Android学习9——ImageButton
- Android学习8之图片按钮ImageButton
- Android学习(三)Button和imageButton
- android ImageButton
- 【android开发笔记】如何让ImageButton去掉白色边框和让ImageButton具有点击效果
- API Demos 2.3 学习笔记 (8)-- Views->ImageButton
- Oracle大数据导出到Access
- 窗体的淡入淡出
- 数据结构--树和二叉树
- inux必学的60个命令
- jpa 查询对象与查询
- Android学习笔记---ImageButton
- vs2008在选择工具箱添加项后自动关闭问题解决
- Android上的Back键事件捕获
- 在对等网络中模拟WCF单工消息交换模式
- 我的第一封博客
- linux学习-unlink
- [C++] 关于C++的cast
- SAP HANA-迅捷企业之选
- 按教程做,新的xcode 4.1 中为何找不到dealloc方法