Adjust icon size of Floating action button (fab)

后端 未结 11 1248
名媛妹妹
名媛妹妹 2020-11-29 17:21

\"Floating The new floating action button should be 56dp x 56dp and the icon inside it should

相关标签:
11条回答
  • 2020-11-29 17:35

    off of @IRadha's answer in vector drawable setting android:height="_dp" and setting the scale type to android:scaleType="center" sets the drawable to whatever size was set

    0 讨论(0)
  • 2020-11-29 17:42

    Try to use app:maxImageSize="56dp" instead of the above answers after you update your support library to v28.0.0

    0 讨论(0)
  • 2020-11-29 17:47

    There are three key XML attributes for custom FABs:

    • app:fabSize: Either "mini" (40dp), "normal"(56dp)(default) or "auto"
    • app:fabCustomSize: This will decide the overall FAB size.
    • app:maxImageSize: This will decide the icon size.

    Example:

    app:fabCustomSize="64dp" 
    app:maxImageSize="32dp"
    

    The FAB padding (the space between the icon and the background circle, aka ripple) is calculated implicitly by:

    4-edge padding = (fabCustomSize - maxImageSize) / 2.0 = 16
    

    Note that the margins of the fab can be set by the usual android:margin xml tag properties.

    0 讨论(0)
  • 2020-11-29 17:47

    You can play with the following settings of FloatingActionButton : android:scaleType and app:maxImageSize. As for me, I've got a desirable result if android:scaleType="centerInside" and app:maxImageSize="56dp".

    0 讨论(0)
  • 2020-11-29 17:48

    The design guidelines defines two sizes and unless there is a strong reason to deviate from using either, the size can be controlled with the fabSize XML attribute of the FloatingActionButton component.

    Consider specifying using either app:fabSize="normal" or app:fabSize="mini", e.g.:

    <android.support.design.widget.FloatingActionButton
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:src="@drawable/ic_done_white_24px"
       app:fabSize="mini" />
    
    0 讨论(0)
  • 2020-11-29 17:48
    <ImageButton
            android:background="@drawable/action_button_bg"
            android:layout_width="56dp"
            android:layout_height="56dp"
            android:padding="16dp"
            android:src="@drawable/ic_add_black_48dp"
            android:scaleType="fitXY"
            android:elevation="8dp"/>
    

    With the background you provided it results in below button on my device (Nexus 7 2012)

    enter image description here

    Looks good to me.

    0 讨论(0)
提交回复
热议问题