【发布时间】:2014-12-29 15:01:08
【问题描述】:
我想知道如何显示仅包含部分 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;
}
}
【问题讨论】:
-
代码的哪一部分不起作用?您无需发布整个代码、GUI 和所有内容 - 只需发布失败的部分即可。
-
没有失败的部分。我的疑问是:如何只显示我想要的 HTML 部分?如何编辑并在我的应用程序中使用它。换句话说,我想加载 HTML 页面,但只显示“用户”、“密码”框和“登录”按钮。谢谢。
-
我从来没有这样做过,所以我不知道如何解决你的问题。作为我之前评论的重述,您应该只发布尝试解决问题的最少代码,而不是您的整个工作解决方案。我希望有人能尽快帮助你!
标签: android eclipse webview android-webview loaddata