首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

WebView显示asset文件夹上自定义文件

2012-08-22 
WebView显示asset文件夹下自定义文件WebView wv (WebView) findViewById(R.id.web)if (wv ! null) {wv

WebView显示asset文件夹下自定义文件

  WebView wv = (WebView) findViewById(R.id.web);        if (wv != null) {                        wv.setBackgroundColor(0x00000000);                    wv.getSettings().setJavaScriptEnabled(true);            wv.addJavascriptInterface(jsVersion, "JSTiVersion");                      String file = "intro.html";            Locale lo = Locale.getDefault();            String lang = lo.getLanguage();            if (lang != null && lang.length() == 2) {                InputStream is = null;                String file2 = "intro-" + lang + ".html";                try {                    AssetManager am = getResources().getAssets();                    is = am.open(file2);                    if (is != null) {                        file = file2;                    }                } catch (IOException e) {                    Log.d(TAG, "Asset not found: " + lang);                } finally {                    if (is != null) {                        try {                            is.close();                        } catch (IOException e) {                            // pass                        }                    }                }            }            wv.loadUrl("file:///android_asset/" + file);            wv.setFocusable(true);            wv.setFocusableInTouchMode(true);            wv.requestFocus();        }        final ProgressBar progress = (ProgressBar) findViewById(R.id.progress);        if (progress != null && wv != null) {            wv.setWebChromeClient(new WebChromeClient() {                @Override                public void onProgressChanged(WebView view, int newProgress) {                    progress.setProgress(newProgress);                    progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);                }            });        }

?

热点排行