Exemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题

    setContentView(R.layout.chromeweblayout);
    mywebView = (WebView) findViewById(R.id.webView1);
    gotoview = (Button) findViewById(R.id.gotoweb);
    urlText = (EditText) findViewById(R.id.urltext);
    urlText.setText("http://qly.wlgj.kp179.com/");
    toolbuttons = (LinearLayout) findViewById(R.id.toolbuttons);
    // urlText.setText("http://61.187.51.109/demo/loginDemo.html");
    WebSettings webSettings = mywebView.getSettings(); // webView: 类WebView的实例
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); // 排版适应屏幕
    webSettings.setLoadWithOverviewMode(
        true); // setUseWideViewPort方法设置webview推荐使用的窗口。setLoadWithOverviewMode方法是设置webview加载的页面的模式。
    webSettings.setUseWideViewPort(true); // 可任意比例缩放
    webSettings.setJavaScriptEnabled(true); // 设置WebView属性,能够执行Javascript脚本
    webSettings.setPluginsEnabled(true);
    webSettings.setAllowFileAccess(true); // 设置允许访问文件数据
    url = "http://www.baidu.com/";
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(false);
    webSettings.setDomStorageEnabled(true);
    mywebView.setWebContentsDebuggingEnabled(true); // 启用调试		
    mywebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    mywebView.requestFocus();
    mywebView.setWebViewClient(
        new WebViewClient() {
          // 新开页面时用自己定义的 webview 来显示,不用系统自带的浏览器来显示
          @Override
          public boolean shouldOverrideUrlLoading(
              WebView view, String url) { // TODO Auto-generated method stub
            // 当有新连接时使用当前的 webview 进行显示
            view.loadUrl(url);
            return super.shouldOverrideUrlLoading(view, url);
          }
        });
    mywebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public Bitmap getDefaultVideoPoster() {
            // TODO Auto-generated method stub
            // return super.getDefaultVideoPoster();
            if (mDefaultVideoPoster == null) {
              mDefaultVideoPoster =
                  BitmapFactory.decodeResource(getResources(), R.drawable.default_video_poster);
            }
            return mDefaultVideoPoster;
          }

          @Override
          public View getVideoLoadingProgressView() {
            // TODO Auto-generated method stub
            // return super.getVideoLoadingProgressView();
            if (mVideoProgressView == null) {
              LayoutInflater inflater = LayoutInflater.from(ChromeWeb.this);
              mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
            }
            return mVideoProgressView;
          }
        });
    mywebView.loadUrl(url);
    gotoview.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            if (!urlText.getText().toString().equals(""))
              mywebView.loadUrl(urlText.getText().toString());
            else mywebView.loadUrl(url);
            urlText.setVisibility(View.GONE);
            v.setVisibility(View.GONE);
            toolbuttons.setVisibility(View.GONE);
          }
        });
    // 添加webview的javascriptInterface接口
    mywebView.addJavascriptInterface(new runCallJavaScript(), "android_js_login");
  }