Chomui
Chomui

Reputation: 13

Android Studio: Floating Action Button: elevation works, but not as it should

I need Circle ImageView with Shadow(elevation) on version >=16, i decided to try FAB.

The problem: If fabsize - normal

If you choose fabCustomSize(75dp)>fabsize(normal) - working, but image are to small: fabcustomsize 75dp

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBlueLightLight"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingActionButton"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:clickable="true"
            app:backgroundTint="#C4C4C4"
            app:borderWidth="0dp"
            app:elevation="4dp"
            app:fabCustomSize="75dp"
            app:fabSize="normal"
            app:rippleColor="#25FAFAFA"
            app:srcCompat="@drawable/mute_2"
            app:useCompatPadding="false" />
    </LinearLayout>

The other two buttons have the same code

Upvotes: 1

Views: 1714

Answers (1)

Khemraj Sharma
Khemraj Sharma

Reputation: 58984

Solution 1

This solution works only for AndroidX, you can read @answer for migrating to AndroidX. Use app:maxImageSize="50dp" in your fab.

output

Solution 2

If you don't want to use AndroidX for now, then put this dimen in your dimens.xml

<dimen name="design_fab_image_size" tools:override="true">70dp</dimen>

Update

Don't set android:layout_width and android:layout_height if you are setting app:fabCustomSize. Then your fab will not be like square.

Upvotes: 0

Related Questions