Why button gets bigger when the background is set in android

前端 未结 6 844
心在旅途
心在旅途 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:49

    You have to distinguish between the size of the Button, its width and height, the whole area you can click on, and the image used for displaying the button.

    The default button on android has a padding applied to its drawable - it seems like it is smaller. It actually has the same size.

    If you make your own drawable and apply no padding, the background will draw within the whole bounds of the view, making it seem bigger.

    You can always just use the default button but apply your own color by using AppCompat. This supports tinting the background of the default button.

     
    

    ...which will let you use the same appearence.

提交回复
热议问题