Android可访问性:如何获得触摸的视图ID?
我已经陷入困境了几天。我想确定用户触摸的观点。这是我的可访问性服务XML:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
android:accessibilityEventTypes="typeViewClicked"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagIncludeNotImportantViews|flagRetrieveInteractiveWindows|flagReportViewIds"
android:canRetrieveWindowContent="true"
android:description="@string/accessibility_service_description_3"
xmlns:android="http://schemas.android.com/apk/res/android"/>
和服务:
@Override
protected void onServiceConnected() {
super.onServiceConnected();
AccessibilityServiceInfo configuration = new AccessibilityServiceInfo();
configuration.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED;
configuration.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
configuration.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
| AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS
| AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
setServiceInfo(configuration);
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
//Toast to show the id of the view that was clicked
Toast.makeText(this, "" + event.getWindowId(), Toast.LENGTH_LONG).show();
}
}
event.getWindowid()
不起作用。我不确定它给出了谁的ID,但它为应用程序中的任何视图提供了相同的ID。我想要用户触摸的视图的ID。
I have been stuck on this for days. I want to identify the view that the user touches. Here is my accessibility service xml:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
android:accessibilityEventTypes="typeViewClicked"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagIncludeNotImportantViews|flagRetrieveInteractiveWindows|flagReportViewIds"
android:canRetrieveWindowContent="true"
android:description="@string/accessibility_service_description_3"
xmlns:android="http://schemas.android.com/apk/res/android"/>
And the service:
@Override
protected void onServiceConnected() {
super.onServiceConnected();
AccessibilityServiceInfo configuration = new AccessibilityServiceInfo();
configuration.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED;
configuration.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
configuration.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
| AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS
| AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
setServiceInfo(configuration);
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
//Toast to show the id of the view that was clicked
Toast.makeText(this, "" + event.getWindowId(), Toast.LENGTH_LONG).show();
}
}
event.getWindowId()
is not working. I'm not sure whose ID it's giving but it gives the same ID for any view inside an app. I want the ID of the view that the user touched.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过
?
Have you tried:
According to the docs: