Android 按钮 Button和ImageButton
Button -- 按钮
ImageButton -- 图片按钮
Button和ImageButton特征
1.共有的特征
都可以作为一个按钮产生点击事件
2.不同点:
(1)Button有text属性,ImageButton没有
(2)ImageButton有src属性,Button没有
3.产生明显的点击效果
实现Button和ImageButton的效果
注:我们一般不把android:text的信息直接写而是放在res/values/strings.xml文件中
在string.xml中添加button_name:
<string name="button_name">登陆</string>
Button通过@string/button_name引用button_name的值:
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_name" />
ImageButton:
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
> <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_name" /> <ImageButton
android:id="@+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" /> </LinearLayout>
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">ButtonImageButton</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="button_name">登陆</string> </resources>
strings.xml
Android 按钮 Button和ImageButton的更多相关文章
- android 设置Button或者ImageButton的背景透明 半透明 透明
Button或者ImageButton的背景设为透明或者半透明 半透明<Button android:background="#e0000000" ... /> 透明 ...
- Android中Button、ImageButton、ImageView背景设置区别
Button与ImageButton实际两者无关,Button继承自TextView,不支持src;ImageButton继承自ImageView.同一张图片在不设置大小,默认显示时,使用Button ...
- android 按钮Button单击背景切换
res/drawable/btn_selected.xml <?xml version="1.0" encoding="utf-8"?> <s ...
- Android监听Button和ImageButton控件的点击事件
一.onClick事件 Button和ImageButton都有一个onClick事件,通过自身的.setOnClickListener(OnClickListener)方法添加点击事件 所有的控件都 ...
- android listview和button,ImageButton等有事件的控件的总结
public ImageButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defSty ...
- Android控件——Button与ImageButton
1.简单介绍
- Android 自定义控件 EditText输入框两边加减按钮Button
自己封装的一个控件:EditText两边放加减按钮Button来控制输入框的数值 Demo 下载地址: 第一版:http://download.csdn.net/detail/zjjne/674086 ...
- android 按钮特效 波纹 Android button effects ripple
android 按钮特效 波纹 Android button effects ripple 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E- ...
- Android 触发Button按钮事件的三种方式
1.新创建一个类 2.使用内部类 3.当多个button按钮时,为简化代码而创建的实例listener 贴代码: MainActivity.Java 文件: package com.android. ...
随机推荐
- Java中常见的异常__
作为一名游戏开发者,程序员,很自然必须熟悉对程序的调试方法.而要调试程序,自然需要对程序中的常见的异常有一定的了解,这些日子很多朋友都提出了很多问题,都是关于游戏中的报错,因此在这里我将一些常见的程序 ...
- org.hibernate.hql.internal.ast.QuerySyntaxExceptionunexpected token: on near line 1
select d.content,count(s.status) from MesmachineStatus s , Mesmachinestatusdetail d where s.status=d ...
- Jquery easyui tree 一些常见操作
Tree: easyui tree的异步加载实现很简单,easyui的中文API文档中有实例(http://api.btboys.com/easyui/)——创建异步树形菜单,就是在tree node ...
- Jquery实现仿腾讯微薄的广播发表
前言: 由于这几天在学习Jquery的一些知识,比以前的感觉就是Jquery太强大了,很多很简单的功能以前在JavaScript要写几十行的代码而在Jquery中只用几行代码就搞定了,所以我决定好好学 ...
- [oracle] 如何使用myBatis在数据库中插入数据并返回主键
在MyBatis中,希望在Oracle中插入数据的同时返回主键值,而非插入的条数. ① oracle使用 selectKey. U_USER_INFO_SEQ 是在数据库中定义好的这张表关联的序列se ...
- foreach、count、explode(对无限级分类的语法注释-显示无限级效果)
foreach ($array as $key => $value) foreach仅能用于数组. 每次循环中,当前单元的键名也会在每次循环中被赋给变量$key. 当前单元的值被赋给$value ...
- Android Studio编译错误:Unexpected lock protocol found in lock file. Expected 3, found 0.
如果不小心手动修改了.gradle文件夹中的内容,那么再打开之前编译成功的工程时,会出现类似下面的错误: Gradle app neame project refresh failed: Unexpe ...
- Spring中 classpath* 和 classpath 前缀的区别
// org.springframework.core.io.support.ResourcePatternResolver /** * Pseudo URL prefix for all match ...
- tomcat:run和tomcat7:run的区别,以及Apache Tomcat Maven Plugin 相关
起因: 同事部署的maven项目,之前使用 jetty,现在切换到 tomcat,但是他使用的命令是 tomcat:run ,而不是 tomcat7:run,能启动,但出现问题了. 于是搜索了一番,想 ...
- CMutex、CCriticalSection、CSemaphore、CEvent、WaitForSingleObject 的小例子
一.CMutex CMutex mutex; mutex.Lock(); // 互斥的动作 // mutex.Unlock(); 二.CCriticalSection CCriticalSection ...