ImageButton与Button
1.Button控件
Butotn控件,主要用来实现一些命令操作,通过注册监听事件来实现。首先需要在xml文档中放入一个button按钮。
<Button
android:id="@+id/button1"
android:layout_width="180dp"
android:layout_height="64dp"
android:layout_x="45dp"
android:layout_y="269dp"
android:background="@drawable/btn01"
android:text="Button" />
Button
可以在xml 中设置该控件的相关属性,包括layout_width等。后台实现的代码为
public class MainActivity extends Activity {
Button myButton;
ImageButton myImg;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myButton=(Button)findViewById(R.id.button1);
textView=(TextView)findViewById(R.id.text1);
myButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
textView.setText("wo lai le");
Toast.makeText(MainActivity.this, "别惦记我", 5000).show();
}});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Button事件
这里通过findViewById()来获取该button控件,为该控件实现setOnClickListener()方法,该方法可以响应button的单击事件。Toast.makeText()来实现弹出提示语言。
2、ImageButton控件
ImageButton控件,可以作为button的另外一种扩展,他可以drawable中显示图标。
ImageButton控件的注册。
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_x="86dp"
android:layout_y="145dp"
android:background="@drawable/easyicon_net_24"
android:src="@drawable/imgbutton" />
ImageButton
可以在注册的时候,设置该控件的各种属性。
本文实现的主要是ImageButton控件的状态改变的时候,变换不同的图片。当鼠标单击的时候显示不同的图片。我们需要在drawable文件夹中加入一个xml文档。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/easyicon_net_24" android:state_pressed="false"></item>
<item android:drawable="@drawable/syicon_net_24" android:state_pressed="true"></item>
</selector>
该文档用来注册imagebutton的不同状态,通过设置android:state_pressed的属性来实现。
ImageButton与Button的更多相关文章
- ImageButton和Button区别
一.基础准备 Imagebutton 继承 Imageview,就是用一个图标代表了一些文字,它没Android:text属性.它由Android:src指定图标的位置 android:s ...
- Android ImageView,ImageButton 与 Button
1. ImageButton 继承自 ImageView.两者具备甚小,因为 ImageView 同样可以点击相应,同样有点击的阴影效果.实际上他们的区别在于默认 style.比如同样放一个背景和一个 ...
- 【读书笔记《Android游戏编程之从零开始》】3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)
3.1 Button Button这控件不用多说,就是一个按钮,主要是点击后进行相应事件的响应. 给组件添加ID属性:定义格式为 android:id="@+id/name",这里 ...
- 2.3.3 Button(按钮)与ImageButton(图像按钮)
本节引言: 今天给大家介绍的Android基本控件中的两个按钮控件, Button普通按钮 ImageButton图像按钮: 其实ImageButton和Button的用法基本类似,至于与图片相关的则 ...
- Flex4 自定义通用的ImageButton
Flex4与之前版本的一个极大区别就是外观皮肤的分离,虽然进一步解耦,但存在一个不爽的地方就是增加了编码的工作量,你能想象为你的每个自定义组件都写一个对应的皮肤吗?可能仅仅和你之前写过的组件差了那么一 ...
- listview中button抢占焦点问题
解决办法Item xml 根节点添加 android:descendantFocusability="blocksDescendants" Button 设置 android:fo ...
- android:ImageView 和ImageButton的区别
1.继承不同: java.lang.Object ↳ android.view.View ↳android.widget.ImageView ↳ android.widget.ImageButton ...
- list view Item 里面有ImageButton
list view Item 里面有ImageButton listview 的item中有ImageButton, 或者 Button. 目的: ImageButton 和 Button的click ...
- Android零基础入门第23节:ImageButton和ZoomButton使用大全
原文:Android零基础入门第23节:ImageButton和ZoomButton使用大全 上一期我们学习了ImageView的使用,那么本期来学习ImageView的两个子控件ImageButto ...
随机推荐
- libaio under MIPS architecture /在mips架构下使用的libaio
First, you can find libaio source in http://libaio.sourcearchive.com/ Second,download the libaio_0.3 ...
- sql server数据库区分大小写设置
数据库表中字段alter Table TableName 区分大小写 ALTER Column ColumnName VARCHAR(50) COLLATE Chinese_PRC_CS_AS不区分大 ...
- 一个SQL 建表格式
CREATE TABLE [dbo].[SysSample]([Id] [varchar](50) NOT NULL,[Name] [varchar](50) NULL,[Age] [int] NUL ...
- jq操作cookie
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ProxyCreationEnabled 和 LazyLoadingEnabled 的关系
我们会使用这两个设置来决定是否加载导航属性.默认情况这两个值都是true的,也就是说会以延迟加载的方式加载导航属性,也就是当我们访问导航属性的时候才会去查数据库获取导航属性的数据.db.Configu ...
- JavaScript实现div宽、高自动缓慢拉伸
最近打算实现一个带有滤镜效果的地自动拉伸图片.发现使用css3浏览器兼容性得需要特别关注.这里我使用js实现了一个div边框自动拉伸和缩小.源码如下: <!DOCTYPE html>< ...
- MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法
MySQL忘记了密码登录不进去,用命令符修改新的密码重新登录的方法: 1.备份my.ini 2.在my.ini字段里 [mysqld] #socket=mysql skip-grant-tables ...
- [汇编语言]-第七章 用[bx+idata]的方式进行数组的处理
1- 转化为大写 方法一: assume cs:code,ds:data data segment db 'BaSiC' db 'MinIX' data ends code segment start ...
- Linux下vim文件未正常退出,修复文件
Linux下vim文件未正常退出,会产生一个 .文件名.swp的文件 ls -al ,rm 删掉.swp文件 之后就可以正常使用文件了
- codeforces 518C. Anya and Smartphone
C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...