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

前端 未结 6 1189
别跟我提以往
别跟我提以往 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:20

    Drawable for "modern" button in XML is @android:drawable/btn_default_material
    It does not exist in android.R.drawable for some reason.

    EDIT: it's private, so don't use it.

    0 讨论(0)
  • 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);
    
    0 讨论(0)
  • 2020-12-30 21:28

    Use this

    b.tr.setBackgroundDrawable(null);
    
    0 讨论(0)
  • 2020-12-30 21:39

    I did it by

    this.setBackgroundResource(android.R.drawable.btn_default);

    0 讨论(0)
  • 2020-12-30 21:40

    Have you tried this?

    android.R.drawable.btn_default;
    
    0 讨论(0)
  • 2020-12-30 21:43

    try

    button.setBackgroundResourses(R.drawable.yourimage);
    

    it will set the default background of buttons. and you can read more default properties of android widgets from given link: https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml

    0 讨论(0)
提交回复
热议问题