开发者

android, is there something like "while key down"?

I want my clickable ImageView to change开发者_如何学运维 its image while it is being pressed and return back to its original image when it is no longer being pressed. What do you think might be the best way for that?

Thanks!


The easiest way (and the way used across the Android framework) is to use state list drawables. This lets you define a single drawable that can change based on states of the view. The one you're looking for is the pressed state. If you supply a state list with a pressed state you will get this behavior without writing any extra code.

More info here: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList


You could use the view's onTouchEvent() API. Make sure that nothing is taking the focus away from the view or it won't get called though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜