Android Studio 之 Intent开发 简单Demo ---- 打开网页
2019-08-22 20:44
2875 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_41811438/article/details/100023857
布局文件main.xml源码如下:
[code]<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn_mybut" android:text="打开网页" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
MainActivity.java源码如下:
[code]package com.example.jimmy.demointent2; import android.content.Intent; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button btn_mybut = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); setContentView(R.layout.main); btn_mybut = (Button)findViewById(R.id.btn_mybut); btn_mybut.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { Uri uri = Uri.parse("http://www.baidu.com"); Intent it = new Intent(); it.setAction(Intent.ACTION_VIEW); it.setData(uri); startActivity(it); } }); } }
点击按钮“打开网页”,直接跳转到百度网页去了。
---- The End.
相关文章推荐
- Android Studio 之 Intent开发 简单Demo ---- 拨打电话
- Android实例demo19之Intent显式意图隐式意图、隐式意图打开多个网页
- 小程序webview嵌入iframe网页demo,微信小程序内嵌iframe网页代码,不支持打开非业务域名,请重新配置
- 基于Flask框架的简单网页开发_2、加入html文件以及css、js文件
- Android Studio配置Kotlin开发环境超级简单方式
- 第71章、再识Intent-打开网页(从零开始学Android)
- 基于AspNet Core2.0(测试版) 开发框架,包含简单的个人博客Demo
- 【Android】Android Studio 快速打开Github上的Demo
- [转载]能ping通但是不能打开网页问题的简单解决方法
- 简单AEDemo开发(一):新建项目
- 使用bootstrap模板开发,网页打开很慢的解决办法
- [置顶] 简单的调用OpenCV库的Android NDK开发 工具Android Studio
- Mac开发 调用浏览器打开网页
- php中检查某个网页地址是否有效能被打开的最简单方法
- C#开发微信公众平台-就这么简单(附Demo)
- 安卓开发学习记录--打开已存在的项目(以Android虹软人脸识别sdk的demo为例)
- 使用Java开源工作流jBPM开发一个简单的Demo
- 第一行代码系列第二章——更多隐式Intent用法(打开网页)
- 移动开发 - Android - 实现两个页面(Activity)的简单跳转(Intent)
- C#开发微信公众平台-就这么简单(附Demo)