gpt4 book ai didi

android - 在 Android 中实现 Webview 的查找以前的功能

转载 作者:搜寻专家 更新时间:2023-11-01 08:28:34 25 4
gpt4 key购买 nike

我制作了一个在 webview 中加载网页的 Xamarin Android 应用程序。我在其中使用了 webview.FindAll 和 webview.FindNext。有谁知道如何在 webview 中实现 Find Previous。这是我的代码:

   using Android.App;
using Android.Widget;
using Android.OS;
using Android.Views;
using System;
using Java.Lang.Reflect;
using System.Collections.Generic;

namespace App1
{
[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{

WebView WebView;
private LinearLayout container;
private Button nextButton, SearchButton;
private EditText findBox;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
WebView = FindViewById<WebView>(Resource.Id.webview);
nextButton = FindViewById<Button>(Resource.Id.btnNext);
SearchButton = FindViewById<Button>(Resource.Id.btnPrev);
findBox = FindViewById<EditText>(Resource.Id.Search);
findBox.SetBackgroundColor(Android.Graphics.Color.White);
findBox.SetTextColor(Android.Graphics.Color.Black);
WebView.Settings.JavaScriptEnabled = true;
WebView.LoadUrl("http://athena.fhict.nl/users/i298536/Index.html");
Search();

}


private void Search()
{

nextButton.Click += delegate

{ WebView.FindNext(true);


};





SearchButton.Click += delegate

{
WebView.FindAll(findBox.Text.ToString());




try
{

Method m = WebView.Class.GetMethod("setFindIsUp", Java.Lang.Boolean.Type);
m.Invoke(WebView, true);
}
catch (Exception ignored) { }

};







}
}

最佳答案

    WebView.FindNext(false); 

它可以返回到之前找到的单词。 同时

        WebView.FindNext(true); 

是去下一个找到的词。

我发这个是为了那些还在寻找答案的人

关于android - 在 Android 中实现 Webview 的查找以前的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42620665/

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