7
我有一個針對事件類型「typeViewTextSelectionChanged」運行的輔助功能服務。我能趕上,只要用戶選擇任何文本此事件觸發,但我如何得到AccessibilityNodeInfo或AccessibilityEvent選定的文本內容對象如何從AccessibilityNodeInfo獲取所選文本
我有一個針對事件類型「typeViewTextSelectionChanged」運行的輔助功能服務。我能趕上,只要用戶選擇任何文本此事件觸發,但我如何得到AccessibilityNodeInfo或AccessibilityEvent選定的文本內容對象如何從AccessibilityNodeInfo獲取所選文本
下面的走了進去,
onAccessibilityEvent(AccessibilityEvent event){}
然後,
//Get the source
AccessibilityNodeInfo source = event.getSource();
//Grab the parent of the view that fired the event.
AccessibilityNodeInfo rowNode = getListItemNodeInfo(source);
//Using this parent, get references to child node, the selected text
AccessibilityNodeInfo textNode = rowNode.getChild(0);
//Get the text values
String text = textNode.getText();
OR
或者在你的情況下,以下應該工作得很好。因爲它是一個「typeViewTextSelectionChanged」事件,顯然它來自EditText。
String text=event.getText();
我似乎無法找到任何getListItemNodeInfo文件,請您鏈接到你見過? – Jayce