开发者

What makes a button change color on mouseclick?

开发者 https://www.devze.com 2023-01-09 15:34 出处:网络
Why is this button changing color to orange when clicked: <Button android:ba开发者_开发技巧ckground=\"@android:drawable/btn_plus\" ...>

Why is this button changing color to orange when clicked:

<Button android:ba开发者_开发技巧ckground="@android:drawable/btn_plus" ...>

but this one is not?

<Button android:background="@drawable/ic_btn_round_plus" ...>   

Edit:

Found another type of button (text and image) that changes color to orange when clicked

without having to create a selector:

<Button android:text="List" android:drawableTop="@drawable/list" ...>       


because the first one is from android framework and has a selector associated to it, and the other one is a custom from your code, and you obviously didn't put a selector on it.
This is nicely explained here. In short you need to put a selector drawable in the background of your button, instead of just one drawable :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/ic_btn_round_plusorange" />
<item android:state_pressed="true" android:drawable="@drawable/ic_btn_round_plusorange" />
<item android:drawable="@drawable/ic_btn_round_plus" />
</selector>

and you create you copy of your drawable but with an orange color added to it for instance. Android system will switch the drawable when the button is clicked or selected.

0

精彩评论

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

关注公众号