网络技术
1.webview的用法
- 在布局文件中建立控件webview用来显示网页
<LinearLayout xmls:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@id/web_view"
android:layout__width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
- 下面是activity代码用findviewbyid()获取webview然后使用setjavascriptenabled()
方法让webview支持JavaScript,这里面小编先跳转到4399页面嘻嘻嘻
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle saveInstanceState){
super.onCreate(savedInstanceState);
serContentView(R.layout.activity_main);
WebView webView=(WebView)findViewById(R.id,web_view);
webView.getSettings().setJavaScriptEnable(true);
webView.loadUrl("http://www.4399.com");
}
}
- 当然了我们需要在AndroidManiffest.xml文件里面添加权限声明,因为我们使用到了网络功能,访问网络是需要声明权限的
<user-permission android:name="android.permission.INTERNET" />