Android WebView从WebViewClient到Activity通信

Android WebView从WebViewClient到Activity通信,第1张

概述我有一个简单的helloworld应用程序.我试图告诉活动用户单击了“ Cnn.com” WebViewClient wc = new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url)

我有一个简单的helloworld应用程序.我试图告诉活动用户单击了“ Cnn.com”

    WebVIEwClIEnt wc = new WebVIEwClIEnt() {        @OverrIDe        public boolean shouldOverrIDeUrlLoading(WebVIEw vIEw,String url) {            if (url.equals("http://cnn.com/")) {                //TELL ACTIVITY CNN WAS CliCKED                return true;            } else {                return false;            }        }    };    mWebVIEw.setWebVIEwClIEnt(wc);

我该怎么做.

(我来自C#.NET背景)

最佳答案
public class YourActivity extends Activity{    // bla bla bla    // the code you already have    WebVIEwClIEnt wc = new WebVIEwClIEnt() {        @OverrIDe        public boolean shouldOverrIDeUrlLoading(WebVIEw vIEw,String url) {            if (url.equals("http://cnn.com/")) {                YourActivity.this.tellMe();                return true;            } else {                return false;            }        }    };    // this is the method to 'tell' the activity that someone clicked the link    public voID tellMe(){        // in this case I just raise a toast.        // but you can do whatever you want here ;)        Toast.makeText(YourActivity.this,"eyy!! somebody clicked the cnn link",1).show();    }}
总结

以上是内存溢出为你收集整理的Android WebView从WebViewClient到Activity通信 全部内容,希望文章能够帮你解决Android WebView从WebViewClient到Activity通信 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1145353.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存