Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make borderless image button small on Android

There is some closeable view in my app and it has a close button in header. I want make this button borderless and small.
The code:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/borderlessButtonStyle"
    android:layout_margin="0dp"
    android:padding="0dp"
    android:src="@android:drawable/ic_menu_close_clear_cancel"/>

In result the button is borderless but has much empty place around cross image (button is hitted on screenshot to make empty space visible)

How could I fix it?

like image 438
Yara_M Avatar asked Jul 28 '26 12:07

Yara_M


2 Answers

You should use:

  android:background="?selectableItemBackgroundBorderless"
like image 100
hrules6872 Avatar answered Jul 30 '26 10:07

hrules6872


Added

 android:minHeight="0dp"
 android:minWidth="0dp"
 android:padding="2dp"

The result

Also I'll use negative margins to place the button closer to corner.

like image 28
Yara_M Avatar answered Jul 30 '26 09:07

Yara_M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!