I am working with the Material Design components in the support library version 28.0.0.
I want to show a snackbar that when the text inside the action button is too long it be shown in a different line than the message of the snack bar.
Following the Material design documentation of these components it seems to be possible using the default snackbar as shown here:
https://material.io/design/components/snackbars.html#implementation
But using this code:
var snackbar:Snackbar = Snackbar.make(root, message, Snackbar.LENGTH_SHORT)
snackbar.setAction(action, View.OnClickListener { })
snackbar.show()
If the action text is long it doesn't move to the next line.
The root layout is a CoordinatorLayout.
So I do not know what I am missing in the snackbar to make it work.
Thanks!
The problem is actually an issue of android itself, the attribute loading from the default android dimen file is broken so the required attribute that is used to calculate the orientation of the elements of the snackbar is never set to the proper value. The issue has been informed and the solution will be pushed to the source code soon.
Workaround: set the attribute maxActionInlineWidth directly in your main theme and you can pickup the values from @dimen/design_snackbar_action_inline_max_width that is the one that should be used by android.
Example:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="maxActionInlineWidth">@dimen/design_snackbar_action_inline_max_width</item>
</style>