Android 通过 “隐式意图” 打开 系统的浏览器 访问 百度页面

在MainActivity中,通过“隐式意图”打开系统的浏览器访问百度页面: MainActivity页面: package cn.lwx.openbrowser;impo

在MainActivity中,通过“隐式意图”打开系统的浏览器访问百度页面:


MainActivity页面:

package cn.lwx.openbrowser;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout._1browser);

        //1、找到按钮 并 设置点击事件
        Button button = (Button) findViewById(R.id.main_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //2、通过隐式意图 开启 系统浏览器
                Intent intent = new Intent();
                //3、设置开启浏览器动作
                intent.setAction("android.intent.action.VIEW");
                //4、设置要打开的网页
                intent.setData(Uri.parse("http://www.baidu"));
                //5、开启页面
                startActivity(intent);
            }
        });

    }
}

_1browser页面:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android/tools"
    android:background="@drawable/openbrowser"
    tools:context=".MainActivity">
    <Button
        android:id="@+id/main_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/click"
        />
</RelativeLayout>


素材(click.png ; openbrowser.png):

效果图:

发布者:admin,转转请注明出处:http://www.yc00.com/web/1741132597a4312409.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信