2014-02-05 53 views
2

如何通過webview顯示單個元素?Android:帶有單個元素的webview

這是我的代碼:

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     WebView wv = (WebView) findViewById(R.id.webView1); 
     WebSettings webSettings = wv.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 
     wv.getSettings().setPluginState(PluginState.ON); 
     wv.getSettings().setAllowFileAccess(true); 
     wv.loadUrl("http://exampleurl.com/"); 
     wv.setWebViewClient(new WebViewClient() { 
       @Override 
       public void onPageFinished(WebView view, String url) { 
        StringBuilder builder = new StringBuilder(""); 
        builder.append("javascript:document.getElementById('header').style.visibility= 'hidden';"); 
        builder.append("javascript:document.getElementsByClassName('pile');"); 
        view.loadUrl(builder.toString()); 
       } 
    }); 
    } 

這是一個形象的例子來我的問題:

image question

順祝商祺!

回答

0

我可以存檔100%的寬度但不是高度,但這可能是因爲我不太瞭解css。對不起,沒有給出完整的答案。

public void onPageFinished(WebView view, String url) { 
    //hide stuff you dont want to see 
    view.loadUrl("javascript:document.getElementById('pilu').style.display = 'none';"); 
    view.loadUrl("javascript:document.getElementById('pilo').style.display = 'none';"); 
    view.loadUrl("javascript:document.getElementById('pila').style.display = 'none';"); 

    //style div to fit screen 
    view.loadUrl("javascript:document.getElementById('pile').setAttribute('style','width:100%;height:100%;');"); 
}