简体   繁体   English

WebView自动更改网址

[英]WebView Changes the Url Automatically

I am very new in App Development with Eclipse for android. 我在Eclipse for Android的App Development中是一个新手。 I am able to make the buttons and links but am stuck at few places, and need help here. 我能够进行按钮和链接,但停留在几个地方,需要帮助。

The App has 3 button and a webview . 该应用程序具有3个按钮和一个webview。

I am loading my Gmail account in webview by clicking the button . 点击按钮将我的Gmail帐户加载到webview中。 these buttonos are shortcuts like Inbox and Junk Box.So i should be able to check the mail by just clicking the inbox button. 这些buttonos是Inbox和Junk Box之类的快捷方式。因此,我应该能够通过单击inbox按钮来检查邮件。

The problems I face are: 我面临的问题是:

  1. When i click the inbox button for first time its ask for username and password but when i click login- It changes the webview Url to something else and ends with not found!! 当我第一次单击收件箱按钮时,它询问用户名和密码,但是当我单击登录时,它会将webview网址更改为其他内容,并以未找到结尾! or error .I want to stop the Url from changing. 或错误。我想停止更改网址。

  2. Webview Opens a new default webbrowser of my phone with the address bar on the top. Webview打开手机的新默认Web浏览器,地址栏位于顶部。 I want to hide that address bar and dont want to use the default browser to open the Page. 我想隐藏该地址栏,并且不想使用默认的浏览器打开页面。 It has to be a smoth transaction without jumoing to URl page. 这必须是一笔不小的交易,而又不涉及URl页面。

Hi Thank you for the response but i have few errors here,1) Since i am using three button , to activate the webview i have used the switch view ,therefore i am not able to define the above below is the sample code: 嗨,谢谢您的答复,但我在这里遇到的错误很少,1)由于我使用的是三个按钮,为了激活Web视图,所以我使用了switch视图,因此我无法在上面定义以下示例代码:

cancelbutton.setOnClickListener(new View.OnClickListener()     {


private Activity result;

            @SuppressWarnings("deprecation")

            public void onClick(View v)   
{
                { switch (v.getId()) 
{
                case R.id.can_button3:  
                Intent myintent1 = new Intent


(Launcher.this,cancelbutton.class); Toast.makeText(Launcher.this, "Cancellation ",

    Toast.LENGTH_SHORT).show();

    setContentView(R.layout.activity_main);

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

    WebView.getSettings().setJavaScriptEnabled(true);

    WebView.getSettings().setSavePassword(true); 

    WebView.loadUrl("https://gmail.com/inbox");break;
} 
} } 
}
);

 junkBox.setOnClickListener(new View.OnClickListener() //Next Button{private Activity 



result;

Create a CustomWebViewClient for your WebView. 为您的WebView创建一个CustomWebViewClient。 Override the following two functions: shouldOverrideUrlLoading - To display the page within WebView onReceivedSslError - To ignore SSL errors. 重写以下两个功能: shouldOverrideUrlLoading在WebView中显示页面onReceivedSslError忽略SSL错误。

The code would look like this: 代码如下所示:

public class CustomWebViewClient extends WebViewClient {

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

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed(); // Ignore SSL certificate errors
    }

}

Add this WebViewClient to your WebView: 将此WebViewClient添加到您的WebView中:

WebView webView = (WebView) result.findViewById(R.id.web_view);
        webView.setWebViewClient(new CustomWebViewClient());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM