android 控件 带图标的按钮(ImageButton)
2014-05-27 21:18
323 查看
1、继承关系和子类:
2、定义:
mageButton就是用一个图标代表了一些文字的Button,它没Android:text属性。它由Android:src指定图标的位置
android:src="@drawable/back_48",其他属性都和Button差不多。
3、XML重要属性:
参考 Button Attributes, View Attributes
android:src="@drawable/xmlbtnback" 将src设置为前面定义好的xml布局
4、重要方法:
5、实战:
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.imageswitcherdemo.MainActivity" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>6、自定义ImageButton显示样式:
6.1自定义xml文件:my_buttton.xml
注意,该文件放到drawable文件夹下。
<?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>
6.2设置的imagebutton的xml布局
android:src="@drawable/my_button"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.imageswitcherdemo.MainActivity" >
<ImageButton
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_button" />
</LinearLayout>
参考1:http://developer.android.com/intl/zh-cn/reference/android/widget/ImageButton.html
参考2:http://www.linuxidc.com/Linux/2011-09/43644p2.htm
2、定义:
mageButton就是用一个图标代表了一些文字的Button,它没Android:text属性。它由Android:src指定图标的位置
android:src="@drawable/back_48",其他属性都和Button差不多。
3、XML重要属性:
参考 Button Attributes, View Attributes
android:src="@drawable/xmlbtnback" 将src设置为前面定义好的xml布局
4、重要方法:
5、实战:
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.imageswitcherdemo.MainActivity" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>6、自定义ImageButton显示样式:
6.1自定义xml文件:my_buttton.xml
注意,该文件放到drawable文件夹下。
<?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>
6.2设置的imagebutton的xml布局
android:src="@drawable/my_button"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.imageswitcherdemo.MainActivity" >
<ImageButton
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_button" />
</LinearLayout>
参考1:http://developer.android.com/intl/zh-cn/reference/android/widget/ImageButton.html
参考2:http://www.linuxidc.com/Linux/2011-09/43644p2.htm
相关文章推荐
- Android UI控件系列:ImageButton(带图标的按钮)
- 【传】玩转Android---UI篇---ImageButton(带图标的按钮)
- Android 控件之四:ImageView 图片框,ImageButton 图片按钮
- 玩转Android---UI篇---ImageButton(带图标的按钮)
- android 学习 ---控件按钮,Button 与ImageButton,
- Android 常用基本控件 ImageButton
- Android 各控件的使用 - 按钮(Button)
- Android - 控件(View)之TextView, Button, ImageButton, ImageView, CheckBox, RadioButton, AnalogClock, DigitalClock 的简单介绍
- Android控件之ZoomButton缩放按钮
- Android - 控件(View)之TextView, Button, ImageButton, ImageView, CheckBox
- android控件06 ImageButton
- Android中设计具有背景图的按钮—ImageButton的焦点及事件处理
- Android学习之Tab控件(使用TabHost和与Tab对应的Menu,动态更改Tabhost的Tab的背景图标,用到Ratingbar控件)
- android 定制个性按钮 控件
- Android中设计具有背景图的按钮—ImageButton的焦点及事件处理
- 【android基础学习之五】——基础控件Menu,Dialog,ImageView,ImageButton
- android自定义按钮控件样式
- Android 控件背景图片和imagebutton的使用(selector)
- 系出名门Android(5) - 控件(View)之TextView, Button, ImageButton, ImageView, CheckBox, RadioButton, AnalogClock, DigitalClock
- Android控件(View)之TextView, Button, ImageButton, ImageView, CheckBox 简单介绍