【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)
}
相关推荐
qhs157324 分钟前
Kotlin字符串操作在Android开发中的应用示例
android·开发语言·kotlin
网络安全(king)2 小时前
Android networkSecurityConfig 代码配置
android
LuXi_foryou2 小时前
【2025深夜随笔】简单认识一下Android Studio
android·ide·android studio
缘来的精彩2 小时前
Android Studio Gradle 8.0 适配指南
android·ide·android studio
星仔_X2 小时前
Android Studio安装配置
android·ide·android studio
驜鸈3 小时前
MySQL 的EXPLAIN 计划 type 字段详细说明
android·数据库·mysql
二流小码农3 小时前
鸿蒙开发:wrapBuilder传递参数
android·ios·harmonyos
ljx14000525504 小时前
推荐一个基于Koin, Ktor & Paging等组件的KMM Compose Multiplatform项目
android·kotlin
lrydnh5 小时前
数据库语句
android·数据库
去看全世界的云5 小时前
【Kotlin】Kotlin基础笔记
android·java·笔记·kotlin