首页 新闻 会员 周边 捐助

关于AccessibilityNodeInfo.setText(CharSequence)

0
悬赏园豆:10 [待解决问题]
 1 package com.lihai.zapp.serv;
 2 
 3 import java.util.List;
 4 
 5 import android.accessibilityservice.AccessibilityService;
 6 import android.annotation.SuppressLint;
 7 import android.view.accessibility.AccessibilityEvent;
 8 import android.view.accessibility.AccessibilityNodeInfo;
 9 
10 @SuppressLint("NewApi")
11 public class MyAccessibilityService extends AccessibilityService {
12 
13     @Override
14     public void onCreate() {
15         super.onCreate();
16     }
17 
18     @Override
19     public void onAccessibilityEvent(AccessibilityEvent event) {
20         switch (event.getEventType()) {
21         case AccessibilityEvent.TYPE_VIEW_FOCUSED:
22             AccessibilityNodeInfo rootNodeInfo = getRootInActiveWindow();
23             List<AccessibilityNodeInfo> nodeInfos = rootNodeInfo.findAccessibilityNodeInfosByText("Button");
24             for (AccessibilityNodeInfo n : nodeInfos) {
25                 n.setText("Change");
26             }
27             break;
28         }
29     }
30 
31     @Override
32     public void onInterrupt() {
33     }
34 }

在这里我想做的是一个当用户开启了辅助功能后能够在我想监听的应用中去改变该应用中一个Button控件的显示文本。但是会报错。求解,setText() 方法的正确使用方式

yipianfan的主页 yipianfan | 初学一级 | 园豆:184
提问于:2015-11-23 00:30
< >
分享
所有回答(1)
0

API>=21

Bundle arguments = new Bundle();

arguments.putCharSequence(AccessibilityNodeInfo .ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "Change");

n.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);

ftionex | 园豆:202 (菜鸟二级) | 2016-01-27 10:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册