Skip to content

Commit af14085

Browse files
committed
[FAB] Add customizable minTouchTargetSize attribute
Resolves material-components#5052
1 parent cc9c4c9 commit af14085

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

lib/java/com/google/android/material/floatingactionbutton/FloatingActionButton.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import com.google.android.material.internal.ThemeEnforcement;
7474
import com.google.android.material.internal.ViewUtils;
7575
import com.google.android.material.internal.VisibilityAwareImageButton;
76+
import com.google.android.material.resources.MaterialAttributes;
7677
import com.google.android.material.resources.MaterialResources;
7778
import com.google.android.material.shadow.ShadowViewDelegate;
7879
import com.google.android.material.shape.ShapeAppearanceModel;
@@ -237,8 +238,6 @@ public FloatingActionButton(
237238
final float pressedTranslationZ =
238239
a.getDimension(R.styleable.FloatingActionButton_pressedTranslationZ, 0f);
239240
compatPadding = a.getBoolean(R.styleable.FloatingActionButton_useCompatPadding, false);
240-
int minTouchTargetSize =
241-
getResources().getDimensionPixelSize(R.dimen.mtrl_fab_min_touch_target);
242241

243242
setMaxImageSize(a.getDimensionPixelSize(R.styleable.FloatingActionButton_maxImageSize, 0));
244243

@@ -254,6 +253,11 @@ public FloatingActionButton(
254253
boolean ensureMinTouchTargetSize =
255254
a.getBoolean(R.styleable.FloatingActionButton_ensureMinTouchTargetSize, false);
256255

256+
int minTouchTargetSize =
257+
a.getDimensionPixelSize(
258+
R.styleable.FloatingActionButton_minTouchTargetSize,
259+
MaterialAttributes.resolveMinimumAccessibleTouchTarget(context));
260+
257261
setEnabled(a.getBoolean(R.styleable.FloatingActionButton_android_enabled, true));
258262

259263
a.recycle();

lib/java/com/google/android/material/floatingactionbutton/res/values/attrs.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
<attr name="fabCustomSize" format="dimension"/>
3939
<!-- Elevation value for the FAB -->
4040
<attr name="elevation"/>
41-
<!-- Whether to extend the bounds of the FloatingActionButton to meet
42-
@dimen/mtrl_fab_min_touch_target. -->
41+
<!-- Whether to extend the bounds of the FAB to meet minTouchTargetSize. -->
4342
<attr name="ensureMinTouchTargetSize"/>
43+
<!-- The minimum size of the FAB's touch target. -->
44+
<attr name="minTouchTargetSize"/>
4445
<!-- TranslationZ value for the FAB when hovered, focused, or hovered and focused. -->
4546
<attr name="hoveredFocusedTranslationZ" format="dimension"/>
4647
<!-- TranslationZ value for the FAB when pressed-->

lib/java/com/google/android/material/floatingactionbutton/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
<item name="android:background">@null</item>
377377
<item name="enforceMaterialTheme">true</item>
378378
<item name="ensureMinTouchTargetSize">true</item>
379+
<item name="minTouchTargetSize">@dimen/mtrl_fab_min_touch_target</item>
379380
<item name="elevation">@dimen/mtrl_fab_elevation</item>
380381
<item name="backgroundTint">@color/mtrl_fab_bg_color_selector</item>
381382
<item name="tint">@color/mtrl_fab_icon_text_color_selector</item>

0 commit comments

Comments
 (0)