【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)
}
相关推荐
来来走走2 分钟前
Android开发(Kotlin) 协程
android·java·kotlin
河铃旅鹿1 小时前
Android开发-java版:Framgent
android·java·笔记·学习
2501_916008895 小时前
手机抓包app大全:无需root的安卓抓包软件列表
android·ios·智能手机·小程序·uni-app·iphone·webview
百锦再5 小时前
第18章 高级特征
android·java·开发语言·后端·python·rust·django
gcygeeker6 小时前
安卓 4.4.2 电视盒子 ADB 设置应用开机自启动
android·adb·电视盒子
小驰行动派7 小时前
安卓上的极简番茄钟 | 开源
android·开源
jzlhll1237 小时前
android抽屉DrawerLayout在2025的沉浸式兼容
android
基哥的奋斗历程7 小时前
Kotlin_Flow_完整使用指南
android·开发语言·kotlin
j***82707 小时前
【玩转全栈】----Django连接MySQL
android·mysql·django
雨白8 小时前
深入理解 Android DocumentFile:性能陷阱与最佳实践
android