博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android---Button
阅读量:7171 次
发布时间:2019-06-29

本文共 1100 字,大约阅读时间需要 3 分钟。

hot3.png

仅供自己练习代码,对看博文的朋友,可能么啥帮助。 

 

1 Add Button xml

res/layout/main.xml 文件中添加 button

2.在activity 中添加如下代码

package com.tutoial.button;import com.tutoial.R;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class TutoialButton extends Activity {	private Button button;		@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		//android 布局		this.setContentView(R.layout.main);				addListenerOnButton();	}	/**	 * 按钮的监听	 */	public void addListenerOnButton(){		button = (Button)findViewById(R.id.buttonOne);		button.setOnClickListener(new OnClickListener() {			@Override			public void onClick(View v) {				//Intent				Intent intent = 						new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.baidu.com"));				startActivity(intent);				Toast.makeText(v.getContext(), "点击进入度娘", Toast.LENGTH_LONG).show();			}		});	}}

 android button

点击后

转载于:https://my.oschina.net/brucechen/blog/59253

你可能感兴趣的文章
【原创】40亿个数字,找出其中出现过两次的字符
查看>>
《Effective C#》快速笔记(二)- .NET 资源托管
查看>>
UVa294 Divisors
查看>>
洛谷P3406 海底高铁
查看>>
HTML学习
查看>>
Warriors of the Visual Studio, Assemble! (Visual Studio的勇士们,汇编吧!)
查看>>
使用Aouth2进行身份验证
查看>>
我们有助教啦
查看>>
一个有关原型的问题牵扯出的问题
查看>>
P53 T3
查看>>
关于 tensorflow-gpu 中 CUDA 和 CuDNN 版本适配问题
查看>>
1、JUC--volatile 关键字-内存可见性
查看>>
LeetCode: Minimum Depth of Binary Tree
查看>>
可运行的代码
查看>>
Oracle数据库添加新字段后加载页面报错 java.lang.IllegalArgumentException
查看>>
CSU 1505: 酷酷的单词【字符串】
查看>>
198. 打家劫舍
查看>>
错误之处(二)
查看>>
CSS选择器 < ~ +
查看>>
Opengl_es模型矩阵位置:glFrustumx与glTranslatef参数的相互影响--立方体旋转特效
查看>>