如何使用小吃店setDuration()方法(Android的设计支持库)
从技术文档:参数持续时间 - 无论是predefined长度之一:LENGTH_SHORT,LENGTH_LONG,或以毫秒为单位的自定义时间。 但我不能设置自定义的持续时间。
From Documentation: parameter duration - either be one of the predefined lengths: LENGTH_SHORT, LENGTH_LONG, or a custom duration in milliseconds. But I can't set custom duration.
例如
Snackbar
.make(parentLayout, "Feed cat?", 8000) // try here
.setAction("Yes", snackOnClickListener)
.setActionTextColor(Color.MAGENTA)
.setDuration(8000) // try here
.show();
但不是8秒小吃吧不见了迅速
but instead of 8 sec Snackbar gone quickly
根据小吃吧的实施
和 SnackbarManager
,我可以证实尤金·H公司的评价:这是一个错误。从 SnackbarManager
:
Based on the implementation of Snackbar
and SnackbarManager
, I can confirm Eugene H's assessment: it's a bug. From SnackbarManager
:
private void scheduleTimeoutLocked(SnackbarRecord r) {
mHandler.removeCallbacksAndMessages(r);
mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_TIMEOUT, r),
r.duration == Snackbar.LENGTH_LONG
? LONG_DURATION_MS
: SHORT_DURATION_MS);
}
因此,任何值不是 LENGTH_LONG
导致短时间的小吃店。
So, any value that is not LENGTH_LONG
results in a short-duration snackbar.
我已经申请问题一下吧
修改:已修复版本22.2.1。检查发行说明这里
Edit: Has been fixed in revision 22.2.1. Check the release notes here
Android的文档有不会尚未更新,但如果你跳进源$ C $ C,你会发现,该参数的方法setDuration(INT持续时间)可以是一个LENGTH_SHORT,LENGTH_LONG, LENGTH_INDEFINITE 或以毫秒为单位的自定义时间
The android docs have NOT been updated yet, but if you jump into the source code you'll notice that the parameter to the method setDuration(int duration) can either be one of LENGTH_SHORT, LENGTH_LONG, LENGTH_INDEFINITE or a custom duration in milliseconds