如何在WebView中编辑HTML?

时间:2014-11-03 00:14:19

标签: android eclipse webview android-webview loaddata

我想知道如何仅使用HTML代码的某些部分来显示页面。登录和密码框,登录按钮......是否可以仅使用WebView执行此操作?

我的代码:

MainActivity.java:

public class MainActivity extends ActionBarActivity {

Button enterButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final WebView myWebView = (WebView) findViewById(R.id.webView1);

WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

myWebView.setWebViewClient(new WebViewClient());

myWebView.loadUrl("http://siga.ufvjm.edu.br");

enterButton = (Button) findViewById(R.id.enterButton);
}


private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (Uri.parse(url).getHost().equals("http://siga.ufvjm.edu.br")) {
        // This is my web site, so do not override; let my WebView load the page
        return false;
    }
    // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    return true;
}
}

1 个答案:

答案 0 :(得分:0)

尝试使用HttpClient加载您的网页:https://stackoverflow.com/a/4457526/3864698

之后,您可以自定义html代码并使用loadDataWithBaseURL设置为WebView。