美文网首页Android
Android两种实现跳转网页的方式

Android两种实现跳转网页的方式

作者: 瑟闻风倾 | 来源:发表于2020-09-26 11:18 被阅读0次

    (1) 方式一

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
            //方式一:代码实现跳转
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            Uri content_url = Uri.parse("https://www.baidu.com/");//此处填链接
            intent.setData(content_url);
            startActivity(intent);
        }
    

    (1) 方式二

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
            //方式二:Webview控件跳转网页
            WebView wv = findViewById(R.id.wv);
            wv.loadUrl("http://www.hao123.com");
        }
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent">
        <WebView
            android:id="@+id/wv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </WebView>
    </LinearLayout>
    

    相关文章

      网友评论

        本文标题:Android两种实现跳转网页的方式

        本文链接:https://www.haomeiwen.com/subject/qvyfuktx.html