question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaterialButton style does not support only Icon

See original GitHub issue

With the use of style Widget.MaterialComponents.Button.Icon I was expecting the layout to format according to icon only but it works just like Widget.MaterialComponents.Button.TextButton.Icon with requirement of adding text also along with icon.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:19
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

52reactions
ymariancommented, Jan 22, 2019

Hi, are you talking about the icon only buttons in the catalog demo? Yes that was a somewhat contentious decision but the reason we have two styles named like that is because the spec defines different paddings for buttons with and without icons. https://material.io/design/components/buttons.html

We don’t provide a style at the moment for Icon Only but you can easily create your own:

eg:

<style name="IconOnlyButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
   <item name="iconPadding">0dp</item>
   <item name="iconGravity">textStart</item>
</style>

21reactions
Dem0n13commented, Sep 20, 2019

I’ve found it more useful:

<style name="Widget.AppTheme.Button.IconButton" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="android:minWidth">0dp</item>
    <item name="android:insetLeft">0dp</item>
    <item name="android:insetTop">0dp</item>
    <item name="android:insetRight">0dp</item>
    <item name="android:insetBottom">0dp</item>
    <item name="iconGravity">textStart</item>
    <item name="iconPadding">0dp</item>
    <item name="iconTint">@drawable/mtrl_btn_text_color_selector</item>
    <item name="rippleColor">?colorOnPrimary</item>
</style>

I reset minWidth to make button square, set rippleColor to show click effect and use mtrl_btn_text_color_selector as iconTint to add disabled state (got from here).

You can set cornerRadius to layout_width/2 and finally get this result:

photo_2019-09-20_13-28-59

Read more comments on GitHub >

github_iconTop Results From Across the Web

Material Button Icon is showing without color - Stack Overflow
The app:icon is tinted with the app:iconTint color provided by the style by default ( Widget.MaterialComponents.Button.UnelevatedButton.
Read more >
MaterialButton - Android Developers
The ".Icon" styles adjust padding slightly to achieve a better visual balance. This style should only be used with a start-aligned icon button....
Read more >
@material/button - npm
MDC Web currently does not support toggle button groups. Icon. Icons can be used as toggle buttons when they allow selection, or deselection,...
Read more >
React Button component - Material UI - MUI
Buttons allow users to take actions, and make choices, with a single tap. Buttons communicate actions that users can take. They are typically...
Read more >
Common buttons – Material Design 3
Icons and labels now share the same color. Icons: Standard size for leading and trailing icons is now 18dp; Shape: Fully rounded corner...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found