Android: How to determine character index of a touch event's position in TextView?

后端 未结 3 1738
陌清茗
陌清茗 2020-12-06 03:04

I have a TextView with an OnTouchListener. What I want is the character index the user is pointing to when I get the MotionEvent. Is t

3条回答
  •  清歌不尽
    2020-12-06 03:09

    I am not aware of a simple direct way to do this but you should be able to put something together using the Paint object of the TextView via a call to TextView.getPaint()

    Once you have the paint object you will have access to the underlying FontMetrices via a call to Paint.getFontMetrics() and have access to other functions like Paint.measureText() Paint.getTextBounds(), and Paint.getTextWidths() for accessing the actual size of the displayed text.

提交回复
热议问题