在Android中实现Webview的Find Previous功能 [英] Implementing Find Previous functionality of Webview in Android

查看:67
本文介绍了在Android中实现Webview的Find Previous功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I made an Xamarin Android Application that loads a webpage in webview. I used webview.FindAll and webview.FindNext in it. Does anyone know how to implement Find Previous in webview. Here are my codes:

   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); 

它可以返回到之前找到的单词.而

it works to go back to the previously found word. while

        WebView.FindNext(true); 

是去下一个找到的词.

我为那些仍在寻找答案的人发布了这个

I posted this for those who are still looking for the answer

这篇关于在Android中实现Webview的Find Previous功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆