如图
设置仅显示单行字符串,末尾用省略号,加跟一个icon,icon可点击
tvName.text = "test"
val drawable = ResourcesCompat.getDrawable(resources, R.mipmap.icon_edit, null)
tvName.setCompoundDrawablesWithIntrinsicBounds(
null, null, drawable, null
)
tvName.setOnTouchListener { v, event ->
val rightDrawable: Drawable = tvName.getCompoundDrawables().get(2)
if (rightDrawable != null && event.getRawX() >= tvName.getRight() - rightDrawable.bounds
.width()
) {
//点击成功
startActivity(MainActivity::class.java)
}
false
}