Android IME,获取EditText实例
我目前正在开发一个输入法,它需要知道文本内容才能计算出光标所在的行和字符等信息。这适用于全屏模式下的提取文本,但我不想强制全屏。这是我当前实现的相关代码
private ExtractEditText mExtract;
......
mExtract = new ExtractEditText(this);
mExtract.setId(android.R.id.inputExtractEditText);
setExtractView(mExtract);
:
@Override public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd) {
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);
String textToMeasure = mExtract.getText().toString().substring(0, newSelStart);
Log.w("myIME", "Line: " + countLines(textToMeasure));
}
I'm currently developing an IME, and it needs to know the text content to work out things like what line and character the cursor is on. This works with the Extract text in fullscreen mode but I would like to not have to enforce fullscreen. Here's related code of my current implementation:
private ExtractEditText mExtract;
...
mExtract = new ExtractEditText(this);
mExtract.setId(android.R.id.inputExtractEditText);
setExtractView(mExtract);
...
@Override public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, int candidatesStart, int candidatesEnd) {
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);
String textToMeasure = mExtract.getText().toString().substring(0, newSelStart);
Log.w("myIME", "Line: " + countLines(textToMeasure));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我查看了 InputMethodService 的源代码,发现它如何提取文本以供 ExtractEditText 使用,因此我能够创建一个解决方案:
I looked in the source of InputMethodService and found out how it extracts the text for the use of the ExtractEditText, thus I was able to create a solution: