Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make custom size of FloatingActionButton

FloatingActionButton by default has two sizes (normal and mini). I need another one (bigger than normal).

app:fabSize parameter from xml became private int mSize; variable in FloatingActionButton class. The real size will be determined by this function:

final int getSizeDimension() {
    switch(this.mSize) {
    case 0:
    default:
        return this.getResources().getDimensionPixelSize(dimen.fab_size_normal);
    case 1:
        return this.getResources().getDimensionPixelSize(dimen.fab_size_mini);
    }
}

Because it declared as final I can not extend it. Any ideas? May be I can redefine dimen.fab_size_mini resource in my app?

like image 455
tse Avatar asked Aug 29 '15 07:08

tse


People also ask

How do you adjust the size of a FloatingActionButton flutter?

To change the size of the floating action button, wrap it with SizedBox() widget and pass custom height and width. SizedBox( height:100, width:100, child:FloatingActionButton( child: Icon(Icons.

How do I make my floating action button smaller?

By default, the floating action button in flutter is 56 logical pixels height and width. This is the normal size or non-mini size. If you add this property mini with a value true, it will create a smaller floating action button.


2 Answers

Since support library 27.1.0 there is an attribute for this:

Just set app:fabCustomSize

like image 190
osrl Avatar answered Sep 20 '22 12:09

osrl


Because I don't use FAB of mini size, I redefined this size.

dimens.xml:

<resources>
    <dimen name="design_fab_size_mini">100dp</dimen>
</resources>

layout.xml (first FAB will be bigger than second one):

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/addPhoto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        app:fabSize="mini"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        android:layout_marginRight="@dimen/fab_margin_right"
        android:src="@drawable/ic_photo_camera_white_24dp"

        />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/addPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@id/addPhoto"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        android:layout_marginRight="0dp"
        android:src="@drawable/ic_photo_white_24dp"
        />
like image 35
tse Avatar answered Sep 21 '22 12:09

tse