I'm working on an application and we want to increase the size of our floating action button on larger devices.
The problem is that floating action button comes only in two size (mini
and normal
).
First, I tried to set a custom android:layout_height
and android:layout_height
to my fab but it didn't work. Well, the whole layout did actually got bigger but a border appeared around the fab and the background wasn't fully transparent.
Desperate for a solution I created my own circle button view and replaced the floating action button. But that's not good enough. I won't have the cool ripple effects or everything else a fab has.
After that, I started reading Floating Action Button's source code but it gets complex really fast so I decided to take a break and post my question here.
So, does anyone know how to increase the size of a floating action button?
EDIT 20/7/2016
My question is indeed similar to this one. However, I ask how to increase the default size of Button, not how to add a new size.
The design library uses these parameters for the Fab:
<dimen name="design_fab_elevation">6dp</dimen>
<dimen name="design_fab_translation_z_pressed">6dp</dimen>
<dimen name="design_fab_content_size">24dp</dimen>
<dimen name="design_fab_size_normal">56dp</dimen>
<dimen name="design_fab_size_mini">40dp</dimen>
<dimen name="design_fab_border_width">0.5dp</dimen>
if you want to use your own Fab you can extend the design support library or copy the whole class and replace your own dimensions in the source code for example at
final int getSizeDimension() {
switch (mSize) {
case SIZE_MINI:
return getResources().getDimensionPixelSize(R.dimen.design_fab_size_mini);
case SIZE_NORMAL:
default:
return getResources().getDimensionPixelSize(R.dimen.design_fab_size_normal);
}
}
But make sure you scale everything so the aspect ratio dose not change.
If you want a quick solution, just define a fab and in code use
float val = 1.3f;
fab.setScaleY(val);
fab.setScaleX(val);
来源:https://stackoverflow.com/questions/34486504/is-it-possible-to-increase-floating-action-button-size-on-android