How to get a Button's background back to default (programmatically)?

前端 未结 6 1235
别跟我提以往
别跟我提以往 2020-12-30 21:06

So I\'m setting a button\'s background doing this:

b.setBackgroundResource(R.drawable.custom_button1);

How do I programmatically set it bac

6条回答
  •  情歌与酒
    2020-12-30 21:24

    first get the default background of Button b; using

    Drawable d = b.getBackground();
    

    then set another background of your choice

    b.setBackgroundResource(R.drawable.custom_button1);
    

    if you need default background again use this

    b.setBackgroundDrawable(d);
    

提交回复
热议问题