How to use setDuration() method in SnackBar (Android Design Support Library)

前端 未结 7 1954
不知归路
不知归路 2020-12-23 16:09

From Documentation: parameter duration - either be one of the predefined lengths: LENGTH_SHORT, LENGTH_LONG, or a custom duration in milliseconds. But I can

7条回答
  •  眼角桃花
    2020-12-23 16:58

    Set the initial duration to LENGTH_INDEFINITE then set your custom duration afterwards:

    Snackbar
    .make(parentLayout, "Feed cat?", Snackbar.LENGTH_INDEFINITE)
    .setAction("Yes", snackOnClickListener)
    .setActionTextColor(Color.MAGENTA)
    .setDuration(8000)
    .show();
    

    EDIT

    Setting a period directly in milliseconds now works;

    Snackbar
    .make(parentLayout, "Feed cat?", 8000)
    .setAction("Yes", snackOnClickListener)
    .setActionTextColor(Color.MAGENTA)
    .show();
    

提交回复
热议问题