Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set margin of actionLayout

The following is the button of my actionLayout. Basically, my actionBar has MenuItems and one of the items has the following button as actionLayout.

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fruit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="15dp"
    android:layout_marginTop="3dp"
    android:background="#999999"
    android:clickable="true"
    android:text="Apple" />

My problem is the height of the button keeps filling the parent. I want to set margins but nothing is working. Does anyone know a simple way to set the margins?

like image 852
Cote Mounyo Avatar asked Dec 05 '25 23:12

Cote Mounyo


1 Answers

You can wrap the button in FrameLayout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
    <Button android:id="@+id/fruit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="50dp"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="3dp"
            android:background="#999999"
            android:clickable="true"
            android:text="Apple" />
</FrameLayout>

And it would look like the following:

device action bar

like image 72
sandrstar Avatar answered Dec 08 '25 15:12

sandrstar



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!