如果文本较长,如何使快餐栏操作按钮显示在不同的行中? [英] How to make that the snackbar action button be shown in a different line if the text is long?

查看:47
本文介绍了如果文本较长,如何使快餐栏操作按钮显示在不同的行中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用28.0.0版支持库中的Material Design组件.

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

但是使用此代码:

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.

根布局是CoordinatorLayout.

The root layout is a CoordinatorLayout.

因此,我不知道小吃店要使它正常工作所缺少的东西.

So I do not know what I am missing in the snackbar to make it work.

谢谢!

推荐答案

问题实际上是android本身的问题,从默认android dimen文件加载的属性已损坏,因此用于计算方向的必需属性快餐栏的元素永远不会设置为适当的值.该问题已得到通知,解决方案将很快推送到源代码.

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.

解决方法:直接在主主题中设置属性maxActionInlineWidth,然后您可以从@ dimen/design_snackbar_action_inline_max_width中获取值,这是android应该使用的值.

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.

示例:

<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>

这篇关于如果文本较长,如何使快餐栏操作按钮显示在不同的行中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆