第71章、再识Intent-打开网页(从零开始学Android)
来源:互联网 发布:mysql中的触发器 编辑:程序博客网 时间:2024/06/07 13:06
调用android内置安装的浏览器来打开网页。
一、设计界面
1、MainActivity布局文件
打开res/layout/activity_main.xml文件。
输入以下代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/open" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打开网页" /></LinearLayout>
二、程序文件
打开“src/com.genwoxue.contentprovider_b/MainActivity.java”文件。
然后输入以下代码:
package com.genwoxue.intenthttp;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity {private Button btnOpen=null;@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnOpen=(Button)super.findViewById(R.id.open); btnOpen.setOnClickListener(new OnClickListener(){ public void onClick(View v) { Uri uri=Uri.parse("http://www.genwoxue.com");//指定网址 Intent intent=new Intent(); intent.setAction(Intent.ACTION_VIEW);//指定Action intent.setData(uri);//设置Uri MainActivity.this.startActivity(intent);//启动Activity } }); }}
三、运行结果
- 第71章、再识Intent-打开网页(从零开始学Android)
- 第69章、初识Intent-打开另一个Activity:单向传值(从零开始学Android)
- 第70章、初识Intent-打开另一个Activity:双向传值(从零开始学Android)
- 第70章、初识Intent-打开另一个Activity:双向传值(从零开始学Android)
- 第72章、再识Intent-调用拨号程序(从零开始学Android)
- 第73章、再识Intent-调用发送短信程序(从零开始学Android)
- 第74章、再识Intent-调用发送彩信程序(从零开始学Android)
- 第75章、再识Intent-调用发送Email程序(从零开始学Android)
- 第76章、再识Intent-调用ContentProviderl程序(从零开始学Android)
- 第77章、再识Intent-创建选择器(从零开始学Android)
- 第4章、打包Android应用(从零开始学Android)
- 第99章、Android调用Javascript(从零开始学Android)
- 第104章、Android访问WebService(从零开始学Android)
- 第4章、打包Android应用(从零开始学Android)
- 第4章、打包Android应用(从零开始学Android)
- 第4章、打包Android应用(从零开始学Android)
- 第99章、Android调用Javascript(从零开始学Android)
- 第9章、图像按钮ImageButton(从零开始学Android)
- github中pull操作
- js 获取url参数的方法
- c++ 循环语句的嵌套的应用
- 指针的指针作用(申请空间)之一
- 第69章、初识Intent-打开另一个Activity:单向传值(从零开始学Android)
- 第71章、再识Intent-打开网页(从零开始学Android)
- redis conf
- 巴科斯范式
- 第72章、再识Intent-调用拨号程序(从零开始学Android)
- 斗兽场防御v1.0.0离线破解+商店破解补丁
- GitHub的使用(上)
- UNIX下STDIN_FILENO与stdin区别
- 第73章、再识Intent-调用发送短信程序(从零开始学Android)
- Shell判断一个目录是否为空