【Android】手写笔适配

以下代码分别用于检测

  • 是否为手写笔事件
  • 是否为橡皮擦事件
  • 是否为手写笔主按钮
  • 是否为手写笔辅按钮
kotlin 复制代码
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
  val isStylus = event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_STYLUS
  val isEraser = event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_ERASER
  val isStylusPrimaryButton = event.buttonState == MotionEvent.BUTTON_STYLUS_PRIMARY
  val isStylusSecondaryButton = event.buttonState == MotionEvent.BUTTON_STYLUS_SECONDARY
  return super.dispatchTouchEvent(event)
}
相关推荐
gxgldyh1 分钟前
Android Framework源码解析(七):BootAnimation 启动流程解析——开机动画是如何显示出来的?
android
达达尼昂21 分钟前
在 Claude Cowork 中用好 Claude Fable 5
android·人工智能·后端
sTone873751 小时前
写时复制COW的第一性理解
android·c++·flutter
sTone873751 小时前
Zygote的第一性理解
android
sTone873751 小时前
类RN框架通过Service暴露卡片渲染能力给AI Chat
android·react native
灯火不休1 小时前
Android Studio & Flutter 构建命令完全指南
android
杉氧1 小时前
Ktor 全栈之路 (5):JWT 认证全流程实战 —— 打造安全通信闭环
android·架构·kotlin
️学习的小王2 小时前
Python + MySQL 学生信息管理系统实战教程
android·python·mysql
帅次2 小时前
Android 高级工程师面试:Flutter 路由导航 近1年高频追问 18 题
android·flutter·面试
alexhilton10 小时前
MVI模式的完整历史、误解和现代Android范式
android·kotlin·android jetpack