i need to set background resource for my button from another button
I am trying it, but it doesn't work
button1.setBackground(button2.getBackground());
i need to set background resource for my button from another button
I am trying it, but it doesn't work
button1.setBackground(button2.getBackground());
Try this code
final Drawable backgroundDrawable = button2.getBackground();
if (backgroundDrawable instanceof BitmapDrawable) {
button1.setBackgroundDrawable(backgroundDrawable);
}else if (backgroundDrawable instanceof ColorDrawable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
final ColorDrawable colorDrawable = (ColorDrawable) backgroundDrawable;
button1.setBackgroundColor(colorDrawable.getColor());
}
}
Hope it will help.