1、WebView的简单使用
安卓程序有的需要浏览网页,因此android提供了一个控件叫WebView,话不多说,直接使用
界面布局代码,就显示一个WebView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="@+id/main_show_webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
处理的代码
public class MainActivity extends Activity {
private WebView mShowWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
//设置隐藏标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mShowWebView=(WebView) findViewById(R.id.main_show_webView);
//通过getSettings进行设置,然后设置支持javaScript
mShowWebView.getSettings().setJavaScriptEnabled(true);
mShowWebView.setWebViewClient(new WebViewClient(){
@Override
//该方法表明如果从当前网页跳转到别的网页