I can not figure out how to make the image fixed 24dp in height and width, so that the button itself was 48dp in height and width. I use SVG as images. android:padding... on the button does not help.

Button:

  <Button android:layout_width="48dp" android:layout_height="48dp" android:background="@drawable/btn_more_vert_black"/> 

Background:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/btn_more_vert_black_pressed" android:state_pressed="true" /> <item android:drawable="@drawable/btn_more_vert_black_default" android:state_focused="true" /> <item android:drawable="@drawable/btn_more_vert_black_default" /> </selector> 

btn_more_vert_black_default - standard icons from the material design library.

  • one
    Padding on the background does not work. In the case of a button, it will work on the text on it. Try replacing the button with an ImageView and programmatically changing the image. Or in xml create a background in which to set the padding and put your svg in the form of a bitmap - YuriiSPb
  • Thank! It worked. I use ImageButton and programmatically put the image. - AndreyEKB

1 answer 1

  1. I use ImageButton:

     <ImageButton android:id="@+id/btn" android:layout_width="48dp" android:layout_height="48dp" android:background="@android:color/transparent"/> 
  2. Programmatically install the image:

     ((ImageButton) findViewById(R.id.btn)).setImageResource(R.drawable.btn_more_vert_black); 

Where btn_more_vert_black picture in svg with the size of 24dp to 24dp