【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)
}
相关推荐
alexhilton4 小时前
用Compose中的Shader实现一个雪花飘飘弹窗效果
android·kotlin·android jetpack
iffy14 小时前
安卓录音方法
android
IT古董5 小时前
【第四章:大模型(LLM)】05.LLM实战: 实现GPT2-(6)贪婪编码,temperature及tok原理及实现
android·开发语言·kotlin
安卓机器8 小时前
安卓10.0系统修改定制化____系列 ROM解打包 修改 讲解 导读篇
android·安卓10系统修改
叽哥9 小时前
flutter学习第 14 节:动画与过渡效果
android·flutter·ios
小仙女喂得猪9 小时前
2025再读Android RecyclerView源码
android·android studio
BoomHe9 小时前
车载 XCU 的简单介绍
android
锅拌饭9 小时前
RecyclerView 缓存复用导致动画失效问题
android
程序员老刘10 小时前
操作系统“卡脖子”到底是个啥?
android·开源·操作系统
拭心10 小时前
一键生成 Android 适配不同分辨率尺寸的图片
android·开发语言·javascript