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的更多相关文章

  1. ImageButton和Button区别

    一.基础准备       Imagebutton 继承 Imageview,就是用一个图标代表了一些文字,它没Android:text属性.它由Android:src指定图标的位置 android:s ...

  2. Android ImageView,ImageButton 与 Button

    1. ImageButton 继承自 ImageView.两者具备甚小,因为 ImageView 同样可以点击相应,同样有点击的阴影效果.实际上他们的区别在于默认 style.比如同样放一个背景和一个 ...

  3. 【读书笔记《Android游戏编程之从零开始》】3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)

    3.1 Button Button这控件不用多说,就是一个按钮,主要是点击后进行相应事件的响应. 给组件添加ID属性:定义格式为 android:id="@+id/name",这里 ...

  4. 2.3.3 Button(按钮)与ImageButton(图像按钮)

    本节引言: 今天给大家介绍的Android基本控件中的两个按钮控件, Button普通按钮 ImageButton图像按钮: 其实ImageButton和Button的用法基本类似,至于与图片相关的则 ...

  5. Flex4 自定义通用的ImageButton

    Flex4与之前版本的一个极大区别就是外观皮肤的分离,虽然进一步解耦,但存在一个不爽的地方就是增加了编码的工作量,你能想象为你的每个自定义组件都写一个对应的皮肤吗?可能仅仅和你之前写过的组件差了那么一 ...

  6. listview中button抢占焦点问题

    解决办法Item xml 根节点添加 android:descendantFocusability="blocksDescendants" Button 设置 android:fo ...

  7. android:ImageView 和ImageButton的区别

    1.继承不同: java.lang.Object ↳ android.view.View ↳android.widget.ImageView ↳ android.widget.ImageButton ...

  8. list view Item 里面有ImageButton

    list view Item 里面有ImageButton listview 的item中有ImageButton, 或者 Button. 目的: ImageButton 和 Button的click ...

  9. Android零基础入门第23节:ImageButton和ZoomButton使用大全

    原文:Android零基础入门第23节:ImageButton和ZoomButton使用大全 上一期我们学习了ImageView的使用,那么本期来学习ImageView的两个子控件ImageButto ...

随机推荐

  1. PHP中的的一个挺好用的函数 array_chunk

  2. JS实现给页面表单设置触发默认按钮

    var defaultBtnId; function setDefaultButton(id) { defaultBtnId = id; } document.onkeydown = function ...

  3. CAS SSO

    1.      CAS 简介 1.1.  What is CAS ? CAS ( Central Authentication Service ) 是 Yale 大学发起的一个企业级的.开源的项目,旨 ...

  4. 使用XE5-PACTH破解Delphi-XE5时,出现检查文件大小失败的解决方法

    今天给自己的64位Win7电脑破解Delphi-XE5时,一直出现检查bds.exe尺寸大小失败的错误提示. 网上查了很久,Csdn上给了个破解的bds.exe,本人一直没什么Csdn积分,没得下,所 ...

  5. 16进制字符串转换为byte数组

    /// <summary> /// 16进制字符转换为byte数组 /// </summary> /// <param name="hexString" ...

  6. autoresizing代码实现

    主要解决父子控件之间的布局关系: /*     Flexible 灵活的,自由的          typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) ...

  7. Linux下MySql出现#1036 – Table ‘ ‘ is read only 错误解决方法

    本文为转载内容,感谢原作者.原文出自:http://zhaoxiaoru39.blog.163.com/blog/static/609552192012511104730115/ 我遇到的问题是:在n ...

  8. hasClass方法 动画方法说明

    $(this).hasClass("selected");判断是否含有selected样式

  9. shell编程笔记(基本部分)

    1.变量 a.需要给变量赋值时,可以这么写: b.要取用一个变量的值,只需在变量名前面加一个$ ( 注意: 给变量赋值的时候,不能在"="两边留空格 ) c.然后执行 chmod ...

  10. progressbar样式

    http://www.oschina.net/question/8676_11797 http://blog.csdn.net/ouyangtianhan/article/details/656576 ...