【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)
}
相关推荐
Co_Hui4 小时前
Android:通知 基本使用
android
古怪今人4 小时前
Android Studio的安装及配置 创建项目编译、运行、调试、打包安装包
android·ide·android studio
程序员陆业聪5 小时前
DNS优化实战:从运营商DNS到HttpDNS的进化之路
android
程序员陆业聪5 小时前
连接优化与复用:让每一次握手都物超所值|Android网络优化系列(3)
android
zhangphil6 小时前
Android Bitmap.Config.HARDWARE属性产生的来源和控制权
android
YF02117 小时前
深度解构Android OkDownload断点续传
android·数据库·okhttp
Co_Hui7 小时前
Android: Service基本使用
android
恋猫de小郭7 小时前
Android Studio 放着没怎么用,怎么也会越来越卡?
android·前端·flutter
Kapaseker7 小时前
Compose 动画 — 显隐的艺术
android·kotlin
黄林晴7 小时前
Android官方发布 AppFunctions,让系统AI直接调用你的APP
android·agent