/** * 初始化内容控件 */
 private void initWeb() {
   // TODO Auto-generated method stub
   String release = android.os.Build.VERSION.RELEASE;
   release = release.substring(0, 3);
   if ("4.4".equals(release)) {
     web_content.setWebViewClient(new MyWebViewClient());
   } else {
     web_content.setVisibility(View.VISIBLE);
     WebSettings ws = web_content.getSettings();
     ws.setJavaScriptEnabled(true);
     ws.setAllowFileAccess(true);
     ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
     ws.setDefaultTextEncodingName("utf-8");
     ws.setTextSize(TextSize.NORMAL);
     ws.setAppCacheEnabled(false);
     ws.setDomStorageEnabled(true);
     if (android.os.Build.VERSION.SDK_INT >= 8) {
       ws.setPluginState(PluginState.ON);
     }
     ws.setRenderPriority(RenderPriority.HIGH);
     web_content.setWebViewClient(new WebViewClientDemo());
     web_content.setWebChromeClient(new WebViewChromeClientDemo());
     web_content.loadDataWithBaseURL("", unit.getIntroduce(), "text/html", "utf-8", null);
   }
 }
Esempio n. 2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fun_everyday, container, false);
    menu = (ImageButton) view.findViewById(R.id.btn_header_left);
    menu.setOnClickListener(this);

    TextView headText = (TextView) view.findViewById(R.id.title_header_mid);
    headText.setText(R.string.text_menu_story);

    String url = "http://www.molegegu.com/im/webview.htm";

    mWebView = (WebView) view.findViewById(R.id.sub_xeb_webview);
    mWebView.loadUrl(url);
    mWebView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });

    mProgressBar = (ProgressBar) view.findViewById(R.id.loadProgress);
    mWebView = (WebView) view.findViewById(R.id.sub_xeb_webview);
    mWebView.loadUrl(url);
    mWebView.setWebViewClient(
        new WebViewClient() {

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
          }
        });
    // set the webview
    WebSettings settings = mWebView.getSettings();
    settings.setSupportZoom(true);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setDefaultTextEncodingName("GBK");
    settings.setTextSize(TextSize.NORMAL);
    settings.setJavaScriptEnabled(true);
    settings.setUseWideViewPort(true);
    mWebView.setInitialScale(80);
    mWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress > 0 && newProgress < 100) {
              mProgressBar.setVisibility(View.VISIBLE);
              mProgressBar.setProgress(newProgress);
            } else if (newProgress == 100) {
              mProgressBar.setVisibility(View.GONE);
            }
          }
        });
    mWebView.requestFocusFromTouch();
    return view;
  }