如何在 webview android SDK 中调用 google 搜索按钮的点击?
我正在制作一个 Android 应用程序,其中包含 webview 和 webview。一个按钮。 webview 将在启动时加载 google.com您应该能够在谷歌搜索框中输入您想要的任何内容,然后单击我的应用程序底部的“搜索”按钮它将调用 webview 内页面上 google 的“Google 搜索”按钮的点击。
问题是......我对 android 开发相当陌生。我不知道如何通过单击布局上的按钮来 getelement classname 调用 Web 视图内部的按钮。
这是“Google 搜索”按钮的代码... http://pastebin.com/NCvnAvb1
另外,下面是 main.xml 布局的示意图
< a href="http://i44.tinypic.com/21jp09g.png" rel="nofollow">http://i44.tinypic.com/21jp09g.png
如果您知道代码,请发表回复,以便我可以在搜索栏中输入一些内容,然后单击布局的搜索按钮&它会搜索谷歌。
谢谢。
编辑:我现在有这个代码...... 但它告诉我“文档无法解析”
webview.evaljs(document.getElementsByClassName("google 搜索按钮 blah").click());
但是现在 eclipse 告诉我“文档无法解析”。
有人知道如何解决这个问题吗?
I'm making an android app that consist of a webview & a button.
The webview will load google.com on startup & your supposed to be able to type anything you want into the google search box, then click on the "Search" button at the bottom of my app & it will invoke a click on google's "Google Search" button that's on the page inside the webview.
Here's the problem... I'm fairly new to android development & I don't know how to getelement classname invoke a click on a button that's inside of the webview by clicking a button on my layout.
Here is the code for the "Google Search" button...
http://pastebin.com/NCvnAvb1
Also, below is a diagram to what the main.xml layout looks like
http://i44.tinypic.com/21jp09g.png
Please post a reply if you know the code so I can type something into the search bar then click on my layout's search button & it will search google.
Thanks.
EDIT: I now have this code...
but it's telling me "document cannot be resolved"
webview.evaljs(document.getElementsByClassName("google search button blah").click());
however now eclipse is telling me "document cannon be resolved".
Anyone know how to fix that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,你的方法是一个坏主意。有可能实现您所要求的目标,但是(我没有考虑如何实现它)您的结果将是脆弱的。 Google 可以更改大约 2843 项内容,从而破坏您的代码。
您可以使用官方 Google API,但仅限于每天 100 次免费查询,除非您注册 Google 结算,在这种情况下,Google 可能会向您收取更多搜索费用。
或者,您可以提供自己的搜索框,可能采用类似于 Google 主页的布局,然后构建搜索 URL 并将其传递回 Google.com
您可能需要考虑使用 Yahoo/Bing,因为它们提供无限的查询。请参阅此处了解详细概述。
In my opinion, your approach is a bad idea. It would be possible to achieve what you're asking, but, (and I haven't thought about how to achieve it) your result would be fragile. There are about 2843 things Google could change which would break your code.
There is an official Google API you can use but you're limited to 100 free queries per day unless you sign up for Google billing, in which case Google might charge you for more searches.
Alternatively, you could provide your own search box, perhaps in a layout that looks like the Google home page, then construct the search URL and pass it back to Google.com
You might want to consider using Yahoo/Bing instead as they provide unlimited queries. See here for a good overview.