Setting the duration of Crouton messages in Android

戏子无情 提交于 2020-01-01 09:38:28

问题


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?


回答1:


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();



回答2:


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.



来源:https://stackoverflow.com/questions/20234873/setting-the-duration-of-crouton-messages-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!