长度不定的Android支持库Snackbar [英] Android Support Library Snackbar with indefinite length

查看:184
本文介绍了长度不定的Android支持库Snackbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到,小吃店在确定其在屏幕上显示的长度时只会采用LENGTH_LONG或LENGTH_SHORT.

I see that the Snackbar will only take either LENGTH_LONG or LENGTH_SHORT when determining the length of its display on screen.

我希望一直显示它,直到有人将其从屏幕上滑出为止.这是在某些情况下出现持续性错误的情况,例如,当您没有互联网并且想要通知用户时,在选择LENGTH_LONG的情况下,希望用户在2750ms后不会消失在屏幕上.

I would like to have it displayed until someone swipes it off the screen. This is for some cases when you have persistent errors, like when you have no internet and you want to notify the user without having it disappearing off the screen after 2750ms when selecting LENGTH_LONG.

我当然可以将setDuration设置为一个非常长的毫秒值,但是没有办法直接设置它,以使它在用户将其关闭之前不会消失吗?

Of course I can use setDuration to a ridiculously long milliseconds values, but is there no way to just set it up so that it doesn't disappears until the user dismisses it?

推荐答案

最新版本的Android支持库( 22.2 .1 ),现在包括 LENGTH_INDEFINITE .

The latest version of the Android Support Library (22.2.1), now includes LENGTH_INDEFINITE.

以下内容将显示Snackbar,直到将其关闭或显示另一个Snackbar.

The following will show the Snackbar until it is dismissed or another Snackbar is shown.

Snackbar.make(view, "Your Snackbar", Snackbar.LENGTH_INDEFINITE)
        .setAction("Your Action", null).show();

这篇关于长度不定的Android支持库Snackbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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