在AccessibilityNodeInfo设置文本 [英] Set text in AccessibilityNodeInfo

查看:5810
本文介绍了在AccessibilityNodeInfo设置文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android辅助服务。我得到了一个 AccessibilityNodeInfo 那些重新presents一个EditText。是不可能性编辑包含的文本?

I'm developing an Android Accessibility Service. I got an AccessibilityNodeInfo that represents an EditText. Is possibile to edit the contained text?

我试着用 mynode.setText(AAA),但我得到 IllegalStateException异常在官方文件中描述< A HREF =htt​​p://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html rel="nofollow">http://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html

I tried with mynode.setText("aaa") but i get IllegalStateException as described in official documentation http://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html

任何想法? 谢谢

推荐答案

您可以使用<一个href="http://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html#ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE"相对=nofollow> ACTION_SET_TEXT 为> =机器人21。 下面是它的例子:

You can use ACTION_SET_TEXT for >= android 21. Here is the example of it:

AccessibilityNodeInfo source = event.getSource();
if (source != null & event.getClassName().equals("android.widget.EditText")) {
    Bundle arguments = new Bundle();
    arguments.putCharSequence(AccessibilityNodeInfo
            .ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "android");
    source.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
}

这篇关于在AccessibilityNodeInfo设置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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