Setting the duration of Crouton messages on Android

I started using Crouton messages instead of toasts because I could adjust the length of time. Is there a way in which I can show the crouton message before a specific event, and not indicate the time in certain units?

+6
source share
2 answers

You can set Crouton duration to INFINITE within Configuration . Then add OnClickListener to it in which you call Crouton.hide(...) as follows:

 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(); 
+19
source

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

+1
source

Source: https://habr.com/ru/post/958902/


All Articles