Change size of icon inside Floating action button

Tobias Sundqvist

New member
Sep 4, 2016
2
0
0
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());
 

Trending Posts

Forum statistics

Threads
956,895
Messages
6,970,492
Members
3,163,642
Latest member
958ryan