admin管理员组文章数量:1287782
在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):
效果图:
版权声明:本文标题:Android 通过 “隐式意图” 打开 系统的浏览器 访问 百度页面 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1741132598a2345388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论