Setting the duration of Crouton messages in Androi

2019-04-08 14:23发布

I have started using Crouton messages instead of toast messages because I could configure the time duration. Is there any way I can keep displaying the crouton message until a particular event rather than specifying the time in definite units?

2条回答
我只想做你的唯一
2楼-- · 2019-04-08 14:48

Instead of using the Crouton library, you can simply add a view and set an onClickListener to it. When the user click on it, the view is removed from the Layout.

查看更多
Rolldiameter
3楼-- · 2019-04-08 15:04

You can set the Crouton's duration to INFINITE from within the Configuration. Then add an OnClickListener to it in which you call Crouton.hide(...) like this:

final Crouton crouton = Crouton.makeText(new Activity(), "foo", Style.ALERT)
    .setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build());

crouton.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    Crouton.hide(crouton);
  }
});

crouton.show();
查看更多
登录 后发表回答