点击时,打开网页

Uri uri = Uri.parse(urlText.getText().toString());

Intent intent = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent);

uri输入应该要合法

package com.example.androidtest;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.EditText;
import android.widget.Button;public class MainActivity extends Activity {private EditText urlText;private Button goButton;public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);urlText = (EditText)findViewById(R.id.url_field);goButton = (Button)findViewById(R.id.go_button);goButton.setOnClickListener(new OnClickListener() {public void onClick(View v) {openBrowser();}});urlText.setOnKeyListener(new OnKeyListener() {public boolean onKey(View view, int keyCode, KeyEvent event){if (keyCode == KeyEvent.KEYCODE_ENTER) {openBrowser();return true;}return false;}});}private void openBrowser(){Uri uri = Uri.parse(urlText.getText().toString());Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);}
}

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><LinearLayoutandroid:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="wrap_content"><EditTextandroid:id="@+id/url_field"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1.0"android:lines="1" /><Buttonandroid:id="@+id/go_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/go_button" /></LinearLayout><WebViewandroid:id="@+id/web_view"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1.0" />
</LinearLayout>

Button的使用(三):处理点击事件相关推荐

  1. android button自动点击事件,Android Button按钮的四种点击事件

    本文实例为大家分享了安卓Button按钮的四种点击事件,供大家参考,具体内容如下 第一种:内部类实现 1.xml里面先设置Button属性 android:id="+@id/button1& ...

  2. 【Vue教程三】点击事件、表单输入事件、键盘事件

    一.点击事件: 1.可以用 v-on 指令监听 DOM 事件,并在触发时运行一些 JavaScript 代码. 'v-on:click' 简写成 '@click' <body><di ...

  3. 按钮button,submit添加鼠标点击事件

    目录 1.直接在按钮处添加onclick属性 2.在表单处添加onsubmit属性 3.操控DOM元素获得组件元素并监听 4.利用jQuery去获得组件元素,使用封装好的click()方法​​​​​​ ...

  4. jQuery 三种点击事件写法

    $("#text").bind("click",function(){alert("hello"); });$("#text1&q ...

  5. js动态添加元素为何 点击事件无效

    本来觉得不用提的,但是发现最近几个朋友在提,而且新来的小兄弟也有点迷糊这个,所以就简单说说, 看看下面的代码: <!DOCTYPE html> <html><head&g ...

  6. android studio listview点击事件,android如何响应listview上不同按钮点击事件

    参考来源:http://www.tuicool.com/articles/bamqiq 大致思路:重写适配器,让主函数继承接口接口 ListItemClickHelp,这个接口中包含onclick方法 ...

  7. Echarts点击事件

    一. 普通点击事件 只有点击折线点或柱子等相应的地方才会触发click事件 myChart.on('click', function (params) {me.clickDailyChart(para ...

  8. vue3组合式写法在方法中出发点击事件

    问: 用vue3组合式写法,如何在一个方法中调用a标签的点击事件 回答: 在Vue 3的组合式API中,可以通过ref来获取DOM元素的引用,然后使用$el属性访问DOM元素并触发其点击事件.下面是示 ...

  9. Android学习笔记(三)——Button之圆角、按压效果、点击事件

    自定义背景形状 圆角按钮 在drawabale 中new一个drawable resource file: 将root element设置为shape,命名为button_2: 在button_2 x ...

最新文章

  1. ci持续集成工程师前景_持续集成CI---失败原因
  2. Atitit hsv转grb  应该优先使用hsv颜色原则 方便人类
  3. Linux进程间通信二 System V 消息队列简介与示例
  4. 【风控术语】数字金融反欺诈技术名词表
  5. (chap9 基于HTTP的功能追加协议) HTTP瓶颈
  6. NYOJ 625 笨蛋的难题(二)
  7. activexobject对象不能创建_面向对象设计方法(Object oriented)
  8. 微信能远程控制电脑吗_牛皮!微信远程控制电脑这个神器太厉害了!
  9. mysql为数据库表起别名的注意事项
  10. 从Ubuntu 14 04 LTS版升级到Ubuntu 16 04 LTS
  11. java中各种时间格式的转化
  12. 寒江独钓——win内核编程读书笔记-1
  13. jQuery使用规范总结
  14. 微信小程序 选项卡 swiper默认高度150px(让高度实现自适应)解决方法
  15. 创建json格式文件
  16. 数据结构-银行业务模拟系统
  17. 300句子与7000单词
  18. 酷客多小程序重磅升级,这十几个模板足以打动你的心!
  19. Ubuntu16.04安装x11vnc服务并设置自动启动
  20. 移动硬盘加密后在linux中如何使用方法,移动硬盘上的文件加密方法

热门文章

  1. 关于android Activity生命周期的说明
  2. python爬虫吧-python爬虫-爬取百度贴吧帖子加图片
  3. python视频课程推荐-听说程序员都在用,5款Python开发工具推荐
  4. python与excel的关系-Python 与 Excel 不得不说的事
  5. python处理表格数据-python通过xrld库读取表格数据
  6. 从零开始学python网络爬虫-从零开始学Python 三(网络爬虫)
  7. python与excel做数据可视化-python操作Excel、读取CVS与数据可视化
  8. python输出csv文件-更高效的Python CSV文件导出
  9. python爬虫百科-Python爬虫之requests库介绍(一)
  10. 学会python爬虫怎么赚钱-转行学Python有前途吗?Python爬虫怎么赚钱?