【我的Android进阶之旅】解决重写onTouch事件提示的警告:onTouch should call View#performClick when a click is detected

一、问题描述

当你对一个控件(例如ImageView)使用setOnTouchListener() 或者是对你的自定义控件重写onTouchEvent方法时会出现这个警告,警告内容全文如下:

MyImageOnTouchListener#onTouch should call View#performClick when a click is detected less… (Ctrl+F1)
If a View that overrides onTouchEvent or uses an OnTouchListener does not also implement performClick and call it when clicks are detected, the View may not handle accessibility actions properly. Logic handling the click actions should ideally be placed in View#performClick as some accessibility services invoke performClick when a click action should occur.

【我的Android进阶之旅】解决重写onTouch事件提示的警告:onTouch should call View#performClick when a click is detected_第1张图片

这段英文翻译过来,大致意思如下:

如果覆盖onTouchEvent或使用OnTouchListener的View没有实现performClick方法,并且在检测到click事件时调用它,则View可能无法正确地处理可访问性操作。处理单击操作的逻辑理想情况下应该放在View#performClick中,因为某

你可能感兴趣的:(我的Android进阶之旅,#)