2.Button按钮实例:普通按钮和图片按钮
目标效果:
布局实现:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/LinearLayout1"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"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" android:background="@drawable/bg5"><Button android:id="@+id/normalButton"android:text="普通按钮"android:textSize="16pt"android:layout_width="wrap_content"android:layout_height="wrap_content"/><ImageButtonandroid:id="@+id/imageButton"android:layout_width="158dp"android:layout_height="wrap_content"android:contentDescription="图片按钮"android:src="@drawable/imagebutton" /><View android:layout_marginTop="20dp"android:layout_width="270dp"android:layout_height="2dip"android:background="#FF909090"/><TextView android:id="@+id/showClickNormal"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="您没有单击普通按钮"android:textSize="20dp"/><TextView android:id="@+id/showClickImage"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="您没有单击图片按钮"android:textSize="20dp"/>
</LinearLayout>
事件响应:
package com.example.buttondemo;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;public class MainActivity extends Activity {Button b1;ImageButton b2;TextView show1;TextView show2;int count1=0;int count2=0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);b1=(Button) findViewById(R.id.normalButton);show1=(TextView) findViewById(R.id.showClickNormal);b1.setOnClickListener(new OnClickListener(){public void onClick(View arg0) {count1++;show1.setText("您一共单击了"+count1+"次普通按钮"); }});b2=(ImageButton) findViewById(R.id.imageButton);show2=(TextView) findViewById(R.id.showClickImage);b2.setOnClickListener(new OnClickListener(){public void onClick(View arg0) {count2++;show2.setText("您一共单击了"+count2+"次普通按钮"); }});}@Overridepublic 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;}}
最终效果:
2.Button按钮实例:普通按钮和图片按钮相关推荐
- 界面组件——按钮(Button)与图片按钮(ImageButton)
介绍 用例 介绍 Button继承了TextView,同时还是ImageButton的父类. Button.ImageButton的功能主要是在UI界面上生成一个按钮,该按钮可以供用户单击,当用户单击 ...
- 【HTML】HTML 表单 ② ( 按钮表单 | 普通按钮 | 提交按钮 | 重置按钮 | 图片按钮 | 文件域 )
文章目录 一.按钮表单 1.普通按钮 2.提交按钮 3.重置按钮 4.图片按钮 二.文件域 一.按钮表单 1.普通按钮 将 <input /> 标签 的 type 属性设置为 button ...
- ToggleButton图片按钮的两种制作方法
第一种: 因为项目需要制作ToggleButton图片按钮,要求点击之后改变图片,而Check和Uncheck的时候又具有Normal.MouseOver.Pressed三种状态. 开始想要利用Vis ...
- JAVA_XXBJ(15)面板添加图片按钮和进度条
很多时候我们使用的并不是文字按钮,更多是使用图片按钮,图片按钮更美观,也更符合界面. 图片按钮 图片按钮的添加也是使用JLabel,JLable所能使用的是文字,图片,图文.那么首先声明一个JLabe ...
- Qt5.9自定义按钮实例(上图片下文字,图片文字间距任意可调)
本博客主要总结一个自定义的按钮实例.该实例实现的效果是上面是图片.下面是文字,其中图片位置和文字位置任意可调. 该自定义控件的实现思路如下: a1.新建一个类,该类继承QPushbutton,由于QP ...
- HTML:a、button、input三种标签下的图片按钮
简述: HTML中以下几种方式可以用来创建一个图片按钮(或是图片超链接): a标签 button标签 input标签中的image类型 下面一一示例. 详解: 1.a标签 a标签用于生成超链接,当内嵌 ...
- html把保留图片改为提交按钮,如何制作图片按钮,并为图片按钮添加提交表单和重置表单功能...
网页中有表单,表单的默认按钮样式不是很好看,很多人为了美观使用图片做按钮. 今天中国在 一.图片按钮的制作方法 1. 定义图像形式的提交按钮. 2.用CSS把图片设为按钮的背景 3.作用,设置其bac ...
- 【AndroidStudio】按钮基本操作(普通按钮、图片按钮、单选按钮设置)(单击事件监听器触发对话框和页面跳转)
普通按钮 普通按钮xml设置: <Buttonandroid:id="@+id/btn"android:layout_width="300dp"andro ...
- 自己写一个图片按钮(XAML)
有时需要用三张图片(正常状态,鼠标移上,鼠标按下)来作为一个按钮的样式,虽然这种做法不好,应该用矢量的方式制作样式,但有的时候还是需要这样做的. 每次都修改按钮的样式来实现这个做法,既麻烦又会生成大段 ...
最新文章
- 服务器 'xxxx' 已被定义为分发服务器。若要将该服务器重新配置为分发服务器,必须首先卸载现有的分发服务...
- python全栈学习--day3
- 取出表A中第31到第40记录
- ABAP search help (搜索帮助) 五种方法
- 福大软工 · BETA 版冲刺前准备(团队)
- 20200714:动态规划复习day05
- VI3之vCenterServer配置的备份与还原
- MySQL 用户表损坏 无法导出数据 无法使用mysql_update mysqd --update=FORCE无效 措施之一
- 大华服务器如何修改IP,大华摄像头更改IP地址
- 山西台达plc可编程控制器_可编程控制器16(PLC)数据移位指令
- 求助各位大神JSP报错急急急!!!!感激不尽
- java连接wamp_eclipse php wamp配置教程
- pta——特立独行的幸福
- a-upload 上传文件到阿里oss
- 力扣解题思路:1419. 数青蛙
- eclipse neon Java编辑器页面字体更改
- 凡吸纳鲁宾逊微积分者,必须遵守“知识共享”授权许可
- web开发技巧-网页排版布局常见问题及解决办法
- Kubernetes网络插件flannel和calico
- python 线程通信的几种方式_Python 线程、线程通信、多线程
热门文章
- python中char是什么意思_MySQL中char和varchar的区别是什么
- Mybatis下传入时间条件,查询慢的优化方法
- sys.path.append()
- 中兴微ZXIC方案MF782型4G随身WIFI开启ADB,开启锁频等功能
- 条码和自动识别的基础知识
- php ping 域名,怎么利用PHP去ping一个地址_PHP
- 微信登录的时候总是显示错误
- MATLAB积分函数integral()的使用方法
- 外贸公司怎么做开发信,什么企业邮箱更适合发开发信呢?
- 青龙面板加xdd-plus机器人保姆级教程