WebView

 1 package com.example.qjm3662.service_learn;
 2 
 3 import android.annotation.SuppressLint;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.util.Log;
 7 import android.view.ActionMode;
 8 import android.view.Menu;
 9 import android.view.MenuItem;
10 import android.view.View;
11 import android.webkit.WebView;
12 import android.webkit.WebViewClient;
13 import android.widget.AbsListView;
14 import android.widget.AdapterView;
15 import android.widget.ArrayAdapter;
16 import android.widget.EditText;
17 import android.widget.ListView;
18 
19 import java.util.ArrayList;
20 import java.util.List;
21 
22 public class MainActivity extends AppCompatActivity implements View.OnClickListener {
23 
24     public static String[] s = new String[10];
25     private WebView webView;
26     private EditText et_input;
27     private static int WEB_POSITION = 0;
28     @SuppressLint("SetJavaScriptEnabled")
29     @Override
30     protected void onCreate(Bundle savedInstanceState) {
31         super.onCreate(savedInstanceState);
32         setContentView(R.layout.activity_main);
33         webView = (WebView) findViewById(R.id.id_webview);
34         et_input = (EditText) findViewById(R.id.id_input);
35         et_input.setOnClickListener(this);
36         s[0] = "http://www.cnblogs.com/qjm253/";
37         //启用javascript支持
38         webView.getSettings().setJavaScriptEnabled(true);
39         webView.getSettings().setBuiltInZoomControls(true);
40         //让WebView自己相应url,将新的url显示在当前view
41         webView.setWebViewClient(new WebViewClient(){
42             @Override
43             public boolean shouldOverrideUrlLoading(WebView view, String url) {
44 
45                 return super.shouldOverrideUrlLoading(view, url);
46             }
47         });
48         webView.loadUrl("http://www.cnblogs.com/qjm253/");
49     }
50 
51     private WebViewClient mWebViewClient = new WebViewClient(){
52         @Override
53         public boolean shouldOverrideUrlLoading(WebView view, String url) {
54             return super.shouldOverrideUrlLoading(view, url);
55         }
56     };
57 
58     @Override
59     public void onBackPressed() {
60         webView.goBack();
61     }
62 
63     @Override
64     public void onClick(View v) {
65         System.out.println("http://" + et_input.getText().toString() + "/");
66         webView.loadUrl("http://" + et_input.getText().toString() + "/");
67     }
68 }

 

 

posted @ 2016-04-23 15:21  阙建明  阅读(215)  评论(0编辑  收藏  举报