Search code examples
javaandroidxmliconsfloating-action-button

how to set icon center in fab in android


how to icon center in com.google.android.material.floatingactionbutton.FloatingActionButton in android ?

when I run the app in normal screen size of mobile then properly show, but I run the app in 10' inch tablet then fab size is small, so how to implement fab properly in any size of the screen in android?

Thanks, in advance.

enter image description here


Solution

  • You have these choices.

    1. Design a separate layout for tablet or large screen devices and set Fab to custom size with this attribute.
    app:fabCustomSize="100dp"
    
    1. Make sure you are not overriding the attribute app:fabSize with value mini or normal. By default your fab size value is fixed to auto
    app:fabSize="auto"
    
    1. Based on how it want to look, you can change the fab to extended by using this <tag
    com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton