ImageButton and EditText
来源:互联网 发布:撤销资阳市知乎 编辑:程序博客网 时间:2024/06/08 14:09
ImageButton与Button类似,区别在于ImageButton可以自定义一张图片作为一个按钮,也正是因为使用了图片作为按钮,所以ImageButton按下与抬起的效果需要自己定义
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ic_launcher" /></RelativeLayout>
package com.example.textavd;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.ImageButton;public class MainActivity extends Activity { ImageButton imagebutton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imagebutton=(ImageButton) findViewById(R.id.imageButton); //为图片设置触屏监听器 imagebutton.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub //用户为按下 if(event.getAction()==MotionEvent.ACTION_DOWN){ 设置图片背景图 imagebutton.setBackgroundDrawable(getResources().getDrawable(R.drawable.a)); }else //用户为抬起 if(event.getAction()==MotionEvent.ACTION_UP){ imagebutton.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher)); } return false; } }); }}
//在上面的 onTouch(View v, MotionEvent event) 的参数说明如下
第一个参数:表示触发出品事件的事件源View
第二个参数:表示触发事件的类型,如按下,抬起,移动
imagebutton.setBackgroundDrawable(getResources().getDrawable(R.drawable.a)
传入图片的ID得到一个Drawable对象。
因为EditText比较简单,所以在这也说一下
<EditText 1.android:numeric="integer" 2.android:maxLines="1" 3.android:singleLine="true" 4.android:password="true" 5.android:hint="66" />
第一个代表只能输入数字
第二个代表输入的最内容
第三个代表输入的内容只能在一行
第四个代表当你输入时是我隐藏的。显示*
第5个代表当你没有输入内容时
阅读全文
0 0
- ImageButton and EditText
- 自定义控件把EditText、TextView、ImageButton
- Button,ImageButton,EditText三控件的应用。
- Android的EditText中添加ImageButton
- Android 之 EditText ImageView ImageButton控件
- ASP.NET ImageButton and OnMouseOver
- 【Android 开发教程】Button,ImageButton,EditText,ChcekBox,ToggleButton,RadioButton
- Android控件——TextView、EditText、ImageView、Button、ImageButton
- 实现editText控件和ImageButton控件的结合
- Button、ImageButton、EditText、CheckBox、ToggleButton、RadioButton和Radio
- Button、ImageButton、和EditText等控件会主动抢夺焦点
- Button、ImageButton、和EditText等控件会主动抢夺焦点
- ImageButton
- ImageButton
- ImageButton
- imagebutton
- ImageButton
- ImageButton
- Apache FTPClient上传下载文件
- MySQL ——JSON相关操作
- springboot下csv文件下载需要注意得一些细节以及功能得完善
- php伪协议
- Switch的用法
- ImageButton and EditText
- ngrok内网穿透服务器和客户端
- FFmpeg系列-0-概述
- DNS初步了解
- 刷博客浏览量
- Redis中AOF持久化
- 美丽的水仙花
- Django入门-搭建开发环境(1)
- 导出Excl