安卓:在浏览器中编辑的文本行为 [英] Android: In browser edit text behavior

查看:453
本文介绍了安卓:在浏览器中编辑的文本行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的下一个问题:

我尝试处理领域的投入,这显示在浏览器中,例如在文本字段在www.google.com搜索。但是为Android 4.1.2及以上的该类型的字段有一些问题InputConnection工作。

I try to process input in field, that displayed in browser, for example in text field for search in www.google.com. But for Android 4.1.2 and above that type of fields work with some problems with InputConnection.

- it return null for ic.getExtractedText() however ic.getTextBeforeCursor() return normal value;
- when i use ic.sendKeyEvent() for backspace it doesn't make effect until call ic.endBatchEdit(); 

但对于普通的EditText或Android的2.3.3它返回正确的值,并删除最后一个字符向右走,甚至直到endBatchEdit()调用;

But for regular edittext or in Android 2.3.3 it return correct value and delete last character right away, even until endBatchEdit() call;

有什么不对的,如何正确的工作,这个领域?
谢谢你。

What's wrong with this and how correct work with this fields? Thanks.

推荐答案

下面链接文件这是在Android杰利贝恩一个已知的bug。
的https://$c$c.google.com / p /安卓/问题/细节?ID = 36152#makechanges

The link here documents this as a known bug on Android Jellybean. https://code.google.com/p/android/issues/detail?id=36152#makechanges

我和几个操作系统版本,并与问题的唯一人试图的确是果冻豆。

I've tried it with several OS versions and the only one with the issue is indeed Jelly Bean.

一个可能的解决方法是使用getTextBeforeCursor()方法,用一个相当大的值的字符数来获得。

A possible work-around is to use the getTextBeforeCursor() method, using a reasonably large value as the number of characters to get.

例如,要查找文本字段中的光标位置如下:

Example to find the cursor position in a text field follows:

            //try with getExtractedText
            extr=ic.getExtractedText(new ExtractedTextRequest(), 0);
            if(extr!=null)
                Log.w("Cursor Pos", "OnKey "+extr.selectionStart);
            else
            {
                String s =ic.getTextBeforeCursor(9999, 0).toString();
                if (s==null)
                    //nothing can be obtained
                else
                    Log.w("Cursor Pos", "OnKey "+(s.length()-1));
            }

这篇关于安卓:在浏览器中编辑的文本行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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