Why button gets bigger when the background is set in android

前端 未结 6 843
心在旅途
心在旅途 2021-02-18 16:15

I encountered a problem with the Button view when I set a background to it using the android:background attribute in xml. Before I set the background,

6条回答
  •  逝去的感伤
    2021-02-18 16:55

    For people looking for doing it in the code (Not in XML), you can use this:

    button.getBackground().setColorFilter(button.getContext().getResources().getColor(R.color.colorAccent), PorterDuff.Mode.MULTIPLY);
    

    this didn't change the size of the button and works with the old android versions too. Several methods discussed here, but this one worked perfect.

提交回复
热议问题