我制作了一个 Xamarin Android 应用程序,可以在 webview 中加载网页。我在其中使用了 webview.FindAll 和 webview.FindNext 。有谁知道如何在 webview 中实现查找上一个。这是我的代码:
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);
就是去下一个找到的单词。
我为那些仍在寻找答案的人发布了此信息
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)