如何将 keyEvent 对象传递给 Button 以使其看起来像被单击?
我制作了一个 SurfaceView 来接受 OnTouchEvent,在这个视图中,我使用 Button.draw(Canvas) 手动绘制一个 Button(不是制作 ViewGroup)。
现在,这个按钮可以在我的SurfaceView上绘制,但是当我将一个keyEvent从OnTouchEvent传递到Button(如Button.onTouchEvent(keyEvent))时,但是这个按钮无法显示点击效果,
所以问题是我如何将keyEvent传递给View手动并显示布局中显示的内容???
有什么想法吗?谢谢!!
i have made a surfaceView to accept a OnTouchEvent,and in this view, i draw a Button manually with Button.draw(Canvas)(not make a ViewGroup).
now, this button can be drawn on my SurfaceView, but when i pass a keyEvent from OnTouchEvent to Button like Button.onTouchEvent(keyEvent), but this button cannot show the click effect
so the question is how can i pass the keyEvent to a View manully and it show what it shown in a Layout????
Any ideas?thx!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确信有更好的方法来做到这一点......但我无法弄清楚。这就是我的想法。
我创建了自己的
Button
扩展。并在我的xmls
中创建MyButton
组件。您需要将
Button
的每个实例更改为com.stackoverflow.android.example.MyButton
。调用
performVirtualClick
函数...就可以了。I'm sure there's a better way to do this...but i couldn't figure it out. So here's what i came up with.
I created my own extension of
Button
. And create components ofMyButton
inside myxmls
.You'll need to change every instance of
Button
tocom.stackoverflow.android.example.MyButton
.Call the
performVirtualClick
function...that'll do.