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?
Setting the duration of Crouton messages in Android
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();
Thank you for your response, but can I call Crouton.hide(crouton) without the on-click listener? I mean to say, can I call just the hide function in an if-branch? –
Orthicon
One more question, do the crouton variables have to be final? Or can we declare in some way using normal declarations. Because, currently, the show and hide methods give error if I try with non-final crouton variables. –
Orthicon
To your first question. You can hide the Crouton any way you want. The second question: Yes, it has to be final, if you're trying to access it from an inner class. –
Leffen
After declaring the croutons in the way you have in the MainActivity class, I am calling an AsyncTask from which I call the show and hide functions from runOnUiThread in doInbackground() function. I keep getting null pointer exception related to croutons. Please tell me how to rectify this? –
Orthicon
This is a different question. Please ask it and include the stack trace there. –
Leffen
how do i add it to a specific view Crouton.makeText(MainActivity.this, "Connected to the interned", Style.INFO, R.id.main_crouton).setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_SHORT).build()).show(); like this ? –
Merchandising
@KaustubhBhagwat this is a separate question. –
Leffen
@keyboardsurfer i want to set duration only .. but to a view i.e R.id.main_crouton which is a framelayout in my activity –
Merchandising
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
.
© 2022 - 2024 — McMap. All rights reserved.