开发者

'Unset' Button background

开发者 https://www.devze.com 2023-02-03 22:26 出处:网络
I\'m changing the background drawable for my buttons when they\'re clicked (as they trigger functions such as play/record). While playing/recording, the button glows (a different 9-patch is set as the

I'm changing the background drawable for my buttons when they're clicked (as they trigger functions such as play/record). While playing/recording, the button glows (a different 9-patch is set as the background) and turns into a stop button. My problem is that currently I'm using:

b.setBackgroundResource(R.drawable.btn_default_normal);

to set the background ba开发者_高级运维ck again afterwards. This works, but the normal behaviour when I use setEnabled(false) is lost. After a button has been used, and reset to normal, it retains the normal background (rather than the dimmed one) when disabled. The text still changes colour though. Is there a way of 'resetting' the background of the button to default, so that it retains its normal behaviour?


Ok, I got the answer from this blog post in the end. What you have to do is create an xml document with all the different button states, and assign that rather than just an image to the background.

0

精彩评论

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

关注公众号