1. Check out our app, Forums for Android! Download and leave feedback here!

Change size of icon inside Floating action button

Discussion in 'App Inventor' started by Tobias Sundqvist, Sep 5, 2016.

  1. Tobias Sundqvist

    Tobias Sundqvist New Member
    Thread Starter
    5

    Sep 5, 2016
    1
    0
    5
    Male
    Tavelsjö
    Hi does anyone know if it is possible to change the size of the icon inside the floating action button programatically?
    It feels like I have searched through the entire internet to find a solution but nope...
    The floating button:
    <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:scaleType="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_camera" />

    The code I have tried:
    FloatingActionButton fab = (FloatingActionButton) v.findViewById(R.id.fab);
    Drawable image = ContextCompat.getDrawable(getContext(),R.drawable.ic_menu_camera);
    image.setBounds(0, 0, 10, 10);
    fab.setImageDrawable(image);

    I also tried to create a scaledDrawable:
    ScaleDrawable sd = new ScaleDrawable(image,0 ,10,10);
    and set the ImageDrawable with fab.setImageDrawable(sd.getDrawable());
     

    Advertisement

Share This Page

Loading...