Android 控件开发之ImageButton
来源:互联网 发布:matlab遗传算法知乎 编辑:程序博客网 时间:2024/05/18 02:18
/**
* 除了Android系统自带的Button按钮一万,还提供了带图标的按钮ImageButton
* 要制作带图标的按钮,首先要在布局文件中定义ImageButton,然后通过setImageDrawable
* 方法来设置要显示的图标。
注意:
我们可以在布局文件中就直接设置按钮的图标,如
android:src="@drawable/icon1"
我们也可以在程序中设置自定义图标
imgbtn3.setImageDrawable(getResources().getDrawable(R.drawable.icon2));
我们还可以使用系统自带的图标
imgbtn4.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_incoming));
设置完按钮的图标后,需要为按钮设置监听setOnClickListener,以此捕获事件并处理
* 除了Android系统自带的Button按钮一万,还提供了带图标的按钮ImageButton
* 要制作带图标的按钮,首先要在布局文件中定义ImageButton,然后通过setImageDrawable
* 方法来设置要显示的图标。
注意:
我们可以在布局文件中就直接设置按钮的图标,如
android:src="@drawable/icon1"
我们也可以在程序中设置自定义图标
imgbtn3.setImageDrawable(getResources().getDrawable(R.drawable.icon2));
我们还可以使用系统自带的图标
imgbtn4.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_incoming));
设置完按钮的图标后,需要为按钮设置监听setOnClickListener,以此捕获事件并处理
*/
ImageButton 效果图:
本程序main.xml源码:
- <?xml version="1.0" encoding="utf-8"?>
- lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- lt;TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="这是一个带图片的按钮.ImageButton"/>
- lt;ImageButton
- android:id="@+id/imageButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- lt;/LinearLayout>
本程序java源码
- package com.sx.ImageButton;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageButton;
- public class ImageButtonActivity extends Activity
- {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- final ImageButton imageButton = (ImageButton)findViewById(R.id.imageButton);
- imageButton.setImageDrawable((getResources().getDrawable(R.drawable.icon)));
- imageButton.setOnClickListener(new Button.OnClickListener()
- {
- @Override
- public void onClick(View arg0)
- {
- //ImageButton事件响应
- }
- });
- }
- }
0 0
- Android 控件开发之ImageButton
- Android 控件开发之ImageButton
- Android 控件之ImageButton、ImageView
- android控件之ImageButton android:scaleType
- Android游戏开发系统控件-ImageButton
- Android基本控件之Button和ImageButton
- Android 之 EditText ImageView ImageButton控件
- Android02--Android之UI控件ImageView+ImageButton
- WPF控件之ImageButton
- android控件06 ImageButton
- Android控件ImageButton设置
- 【读书笔记《Android游戏编程之从零开始》】3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)
- Android - 控件(View)之TextView, Button, ImageButton, ImageView, CheckBox
- 一步一步学android控件(之九) —— ImageButton
- Android 控件之四:ImageView 图片框,ImageButton 图片按钮
- android 之ImageButton OnTouchListener
- Android之ImageButton、ImageView
- Android复习之ImageButton
- C#高级编程五十六天----可观察的集合ObservableCollection
- 关于cocoaPods
- const指针与指向const对象的指针
- int *p=12这里是不可以这样做的,指针要开辟空间
- SDWebImage情况处理(不断更行)
- Android 控件开发之ImageButton
- 软件开发工具(三)——理论与开发过程
- iOS实现感知哈希算法
- 求最大公约数
- Google跨域配置
- iOS开发基础知识:Core Animation(核心动画)
- Android 控件开发之 RadioButton
- c++里,输入输出方式
- PAT (Advanced Level) 1053. Path of Equal Weight (30) 求树根到叶子和为所给数值的路径,DFS后排序