Android系列二、WebView

作者: 大河_大河 | 来源:发表于2017-01-23 12:29 被阅读80次

一、修改layout文件

1、打开src->main->res->layout->activity_main.xml文件,删除TextView的节点。添加如下代码:

   <WebView
        android:id="@+id/testWebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

其中match_parent表示和父窗体的大小一样。id为:testWebView。

WebView

2、MainActivity文件中:

MainActivity

这时候运行会报网络连接的错误。是因为我们没有设置网络连接的权限。

3、在AndroidManifest.xml中的manifest 节点添加一个子节点:

 <uses-permission android:name="android.permission.INTERNET"></uses-permission>

如图:


AndroidManifest.xml

4、运行后:

运行效果

相关文章

网友评论

    本文标题:Android系列二、WebView

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