gpt4 book ai didi

java - 在网页中搜索..Android

转载 作者:行者123 更新时间:2023-11-30 03:40:08 25 4
gpt4 key购买 nike

我需要在网页中搜索..我开发了android应用程序..其中当用户按下按钮时网页将被打开但我需要用户输入关键字并且当用户按下按钮时关键字必须在网页内搜索..我在这里提供我的 coe 你能建议我下一步要做什么吗

Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=(Button) findViewById(R.id.button1);
ev = (EditText) findViewById(R.id.editText1);

btn1.setOnClickListener(new View.OnClickListener()
{


@Override
public void onClick(View v)

{
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.androidaspect.com"));

startActivity(intent);
}
});
}

最佳答案

首先,您需要将 url 加载到您的 WebView 中.然后使用 javascript in your Webview寻找。您可以使用此 javascript 进行搜索

$(document).ready(function() {
function trim(value) {
var temp = value;
var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
if (obj.test(temp)) {
temp = temp.replace(obj, '$2');
}
var obj = / +/g;
temp = temp.replace(obj, " ");
if (temp == " ") {
temp = "";
}
return temp;
}
var body = $('body');

SearchQueue("of Micro");

function SearchQueue(text) {
if (text !== null) {
text = text.replace(/^\s*$[\n\r]{1,}/gm, ''); // Removing empty line breaks
text = text.replace(/”/g, "\"");
text = text.replace(/“/g, "\"");
text = text.replace(/”/g, "\"");
text = text.replace(/’/g, "\'");
text = text.replace(/‘/g, "\'");
text = text.replace(/–/g, "\-");
text = text.replace(/—/g, "\-");
text = text.replace(/–/g, "\-");
var txt1 = text;
text = trim(txt1);
var SearchItems = text.split(/\r\n|\r|\n/);
var replaced = body.text();
for (var i = 0; i < SearchItems.length; i++) {
var tempRep = '<span class="highlight" style="background-color: yellow">';
tempRep = tempRep + SearchItems[i];
tempRep = tempRep + '</span>';
replaced = replaced.replace(SearchItems[i], tempRep);
}
$("body").html(replaced);
}
}
shortcut.add("Ctrl+Z", function() {
$('.highlight').toggleClass();
});

shortcut.add("Ctrl+V", function() {
var txt = window.clipboardData.getData("Text");
var ClipText = txt.replace(/[a-zA-Z0-9\?\&\=\%\#]+s\=(\w+)(\&.*)?/, "$1");
SearchQueue(ClipText.replace(/\%20|\+/g, "\|"));
});
});

关于java - 在网页中搜索..Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15899957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com