【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)
}
相关推荐
晚风叙码7 小时前
MySQL 表的约束详解:从空属性到外键
android·数据库·mysql·adb
alexhilton17 小时前
模块化Jetpack Compose架构
android·kotlin·android jetpack
厮年断弦19 小时前
AI 辅助开发实录:一周做完一个 Android 本地音乐播放器,这些坑替你踩了
android
hai_android19 小时前
InputStage 责任链核心执行流程
android·android studio·android jetpack
mmsx1 天前
Android 测绘计算工程化:七四参数、高程拟合与单位系统
android·kotlin
我是场1 天前
我的NPI项目之-Touch的EE特性
android·arm开发
天空之城--1 天前
Android一周动态:AI编程、Compose与车载生态新信号
android·flutter
恋猫de小郭1 天前
Dart 4.0 要彻底移除 dart:mirrors,Augmentations 应该要来了
android·前端·flutter
Carson带你学Android1 天前
Gemini 4 Argon 发布:对 Android 开发者意味着什么?
android·ai编程
事圆则缓1 天前
Kotlin Flow、StateFlow、SharedFlow 全解析:冷流、热流与 Android 状态管理
android·kotlin·php