Context sensitive notifications for Android

Last update: May 11, 2022

Crouton

Crouton

Context sensitive notifications for Android

DEPRECATION NOTICE

This library has passed it's prime and is now considered deprecated.

With the Android Design Support Library introducing Snackbar developers get a well crafted pattern to use for context aware notification of users.

I won't do any active development for Crouton any more. But I still do accept pull requests that fix bugs.

So long, and thanks for all the forks.

Overview

Crouton is a class that can be used by Android developers that feel the need for an alternative to the Context insensitive Toast.

A Crouton will be displayed at the position the developer decides. Standard will be the top of an application window. You can line up multiple Croutons for display, that will be shown one after another.

You can check some features in the Crouton Demo.

Crouton Demo on Google Play

If you're already using Crouton and just want to download the latest version of the library, follow this link.

Releases / Changelog

Current version: 1.8.5

Usage

The API is kept as simple as the Toast API:

Create a Crouton for any CharSequence:

Crouton.makeText(Activity, CharSequence, Style).show();

Create a Crouton with a String from your application's resources:

Crouton.makeText(Activity, int, Style).show();

Further you can attach a Crouton to any ViewGroup like this:

Crouton.makeText(Activity, int, Style, int).show();

Crouton.makeText(Activity, int, Style, ViewGroup).show();

Also Crouton.show(...) methods are available for convenient fire and forget display of Croutons.

If you would like a more graphical introduction to Crouton check out this presentation.

##Important!

In your Activity.onDestroy() make sure to call

Crouton.cancelAllCroutons();

to cancel cancel all scheduled Croutons.

This is a workaround and further description is available in issue #24.

Basic Examples

Currently you can use the three different Style attributes displayed below out of the box:

Alert

Confirm

Info

Extension and Modification

The whole design of a Crouton is defined by Style.

You can use one of the styles Crouton ships with: Style.ALERT, Style.CONFIRM and Style.INFO. Or you can create your own Style.

In general you can modify

  • display duration
  • dimension settings
  • options for the text to display
  • custom Views
  • appearance & disappearance Animation
  • displayed Image

Since Style is the general entry point for tweaking Croutons, go and see for yourself what can be done with it.

Building

Gradle

From maven central

Add maven central to your build.gradle:

buildscript {
  repositories {
    mavenCentral()
  }
}
 
repositories {
  mavenCentral()
}

Then declare Crouton within your dependencies:

dependencies {
  ...
  compile('de.keyboardsurfer.android.widget:crouton:[email protected]') {
    // exclusion is not necessary, but generally a good idea.
    exclude group: 'com.google.android', module: 'support-v4'
  }
  ...
}

Maven

From maven central

To use crouton within your maven build simply add

<dependency>
  <artifactId>crouton</artifactId>
  <version>${crouton.version}</version>
  <groupId>de.keyboardsurfer.android.widget</groupId>
</dependency>

to your pom.xml

If you also want the sources or javadoc add the respective classifier

  <classifier>sources</classifier>

or

  <classifier>javadoc</classifier>

to the dependency.

If you are referencing a newer version of the Android Support Library in your application, you might want to exclude Crouton's dependency like this:

<dependency>
	<artifactId>crouton</artifactId>
	<version>${crouton.version}</version>
	<groupId>de.keyboardsurfer.android.widget</groupId>
	<exclusions>
	    <exclusion>
	        <groupId>com.android.support</groupId>
	        <artifactId>support-v4</artifactId>
	    </exclusion>
	</exclusions>
</dependency>

DIY

The build requires Gradle. Operations are very simple:

  • install gradle
  • gradle assemble builds all artifacts
  • gradle jar builds the jar

After putting Crouton in a repository you can add it as dependency.

compile('de.keyboardsurfer.android.widget:crouton:[email protected]') {
  exclude group: 'com.google.android', module: 'support-v4'
}

###Building and Signing

In order to build and sign Crouton locally you'll need to rename gradle.properties.sample to gradle.properties.

Contribution

###Questions

Questions regarding Crouton can be asked on StackOverflow, using the crouton tag.

Pull requests welcome

Feel free to contribute to Crouton.

Either you found a bug or have created a new and awesome feature, just create a pull request.

If you want to start to create a new feature or have any other questions regarding Crouton, file an issue. I'll try to answer as soon as I find the time.

Please note, if you're working on a pull request, make sure to use the develop branch as your base.

Formatting

For contributors using Eclipse there's a formatter available at the download section.

In order to reduce merging pains on my end, please use this formatter or format your commit in a way similar to it's example.

If you're using IDEA, the Eclipse Formatter plugin should allow you to use the formatter as well.

License

Attributions

The initial version was written by Benjamin Weiss. The name and the idea of Crouton originates in a blog article by Cyril Mottier.

The Crouton logo has been created by Marie Schweiz.

GitHub

https://github.com/keyboardsurfer/Crouton
Comments
  • 1. Problem with ListActivity and Crouton

    I'm actually working on an app and i want to use the Crouton library. So i decide to replace my Toast by this and all is right. Yet, i discover a problem with my ListActivity. I start an activity which needs internet connection so if it is not the case, i display a Crouton.

    And when i display a Crouton i can no longer click on listview items.

    ps : I use it with ActionBarSherlock

    Reviewed by aat-antoine at 2012-11-12 17:05
  • 2. Action bar overlay?

    How do you handle repositioning of a crouton when action bar overlay is on?

    I have a weird case where the crouton goes below my action bar. My hacky solution for now is to add a custom view and add top padding when the action bar is visible?

    Is that something that this library doesn't handle automatically? or am I doing something wrong?

    Thanks

    Reviewed by aryaxt at 2014-03-18 23:39
  • 3. Crouton "destroys" PreferenceFragment

    This is how my PreferenceFragment looks like: https://picasaweb.google.com/lh/photo/QbpRCxQHqVATtMqhpP7OPhehlnpMhIUyAwoYnhPIGog?feat=directlink When showing a Crouton: https://picasaweb.google.com/lh/photo/MJwaGoIBiO7NNtpmprypnBehlnpMhIUyAwoYnhPIGog?feat=directlink

    Reviewed by gabrielittner at 2012-09-06 14:01
  • 4. NoClassDefFoundError

    I'v some problems using your lib, i got a error

    NoClassDefFoundError: de.keyboardsurfer.android.widget.crouton.Style.
    

    I tried the lib with maven and with a jar combiled by gradle, the same error

    I' Downloaded the demo app on Google Play : Same Error on CroutonDemo Class (ICS 4.0.3 Device)

    Reviewed by adenaud at 2014-01-24 14:06
  • 5. Orientation changes prevent the Crouton queue to be displayed correctly.

    If there are a few Croutons within the queue and the device's orientation changes, all Croutons that have not yet been displayed will not be displayed.

    Also Croutons that get added to the queue will not be displayed until the pre-orientation change queue has been fully processed.

    This issue exists since the initial version of Crouton.

    Reviewed by keyboardsurfer at 2012-09-18 08:12
  • 6. Gradle error with the latest build tools

    With today's update of the build tools, SDK and library-support, Crouton doesn't compile anymore from Maven:

    Error:Module version de.keyboardsurfer.android.widget:crouton:1.8.4 depends on libraries but is not a library itself
    

    I use in my build.gradle file the following:

    compile('de.keyboardsurfer.android.widget:crouton:1.8.4') {
         exclude group: 'com.google.android', module: 'support-v4'
    }
    
    Reviewed by lynfogeek at 2014-06-26 19:55
  • 7. Added Configuration - Seperating out duration from style

    Style is too limiting and the wrong name now. It contains aspects which should be available to none styled croutons.

    Configuration file is dependant to Style/CustomView meaning we can set a duration on the Custom views!! Yay!

    Please note, Only look at the last commit. I can cherry pick for you if you would like?

    This now allows Crouton.make(Activity,View,ViewGroup, Config) Or Crouton.make(Activity,View,ViewGroup).setConfiguration(Config.Builder().build()).show()

    And of course added to showText Method so users can define non default config.

    Feel free to ask questions. Or implement the concept slightly differently.

    Commit as follows: Separated out the Non Visual config from Style, Configuration is dependant of how the crouton is displayed.

    Issue being the duration (and potentially other items) should not be tied to the Visual aspect.

    Cherry Picked from upstream & master and merged.

    Reviewed by chrisjenx at 2013-03-29 21:25
  • 8. Crashes in L Preview

    I know its a preview, but I'd like to make sure our app works in L. And Crouton doesn't seem to right now. Here's the stack trace on attempting to display a Crouton:

    java.lang.UnsupportedOperationException: addContentView does not support content transitions at com.android.internal.policy.impl.PhoneWindow.addContentView(PhoneWindow.java:394) at android.app.Activity.addContentView(Activity.java:2170) at de.keyboardsurfer.android.widget.crouton.Manager.addCroutonToView(Manager.java:216) at de.keyboardsurfer.android.widget.crouton.Manager.handleMessage(Manager.java:164) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5070) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)

    Reviewed by roms at 2014-07-29 23:26
  • 9. Crouton vs HoloEverywhere

    When using HoloEverywhere Croutons are displayed on whole screen. This occurs even after changing all references to HoloEverywhere classes.

    My question is just if you haven't tried Croutons on HoloEverywhere. Thx

    Reviewed by MartinRajniak at 2013-02-19 10:14
  • 10. Crouton translucent status bar position.

    Hello i am using translucent statusbar in my app without using fitsSystemBar. I am using system tint bar lib for adding top padding to android.R.id.content, but Crouton place under actionbar + this padding. This is screenshot

    screenshot_2014-02-06-02-58-01

    Reviewed by mecid at 2014-02-05 22:59
  • 11. Does not compile with Gradle

    $ gradle assemble Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties. Deprecated dynamic property: "artifactId" on "project ':crouton-library'", value: "crouton".

    FAILURE: Build failed with an exception.

    • Where: Build file '/Users/code/studio/libraries/Crouton/library/build.gradle' line: 96

    • What went wrong: A problem occurred evaluating project ':crouton-library'.

      No such property: repositoryUrl for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer Possible solutions: repository

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    BUILD FAILED

    Total time: 3.749 secs

    Reviewed by powder366 at 2014-09-27 08:42
  • 12. How to use Crouton.makeText in AsyncTask

    private class TestTask extends AsyncTask<Object, String, Boolean> {
            @Override
            protected Boolean doInBackground(Object... objects) {
                //....
                return true;
            }
    
            @Override
            protected void onPostExecute(Boolean aBoolean) {
                //....
                Crouton.makeText(??, "Some text", Style.ALERT).show();
        }
    
    Reviewed by NMelis at 2019-06-19 00:41
  • 13. Crouton Not work when app come background nearly after 2 mins

    Crouton Not work when app come background nearly after 2 mins. When remove from memory and start again it's work perfect.

    if user come background in 20 seconds it is not problem again work perfect.

    Do you have any idea how can i solve that ?

    Reviewed by kaganbzkrt at 2018-05-14 20:26
  • 14. SpannableString or Html tags ?

    Hi guys,

    I'm looking for a way to have a text that is mid bold mid italic. It seems impossible at the moment, because there is not method to do that and I can't touch the textview of crouton properly.

    Should I made a PR ?

    Reviewed by adrienrx at 2017-03-14 12:21
  • 15. Fixed memory leak in DefaultAnimationsBuilder

    When the animations get run there is a Handler that gets set on the Animation (Animation.mListenerHandler). This Handler holds a reference to the Activity. So caching the animations in a static field causes the Activity to be leaked. The fix was to remove the static fields that were caching the animation. Now the animations are created new each time.

    Reviewed by jferlisi at 2015-09-28 15:29
  • 16. memory leak in DefaultAnimationsBuilder.java

    final class DefaultAnimationsBuilder { private static final long DURATION = 400L; private static Animation slideInDownAnimation; // memory leak, hold on activity private static Animation slideOutUpAnimation; // memory leak, hold on activity ... }

    If you use leakcanary (https://github.com/square/leakcanary), you can detect this memory leak.

    Please check it. Thanks.

    Reviewed by soxunyi at 2015-07-12 11:00
Related tags
An android library for easy implementation of Toasts in Android with easy customisation.
An android library for easy implementation of Toasts in Android with easy customisation.

ToastTypeDecore Šī¸ A library for easy implementation of Toasts in Android with easy customisation. Latest Version : v2.1 Screenshots Success Toast1 Su

Oct 27, 2021
Android : IamToast Another Toast library for Android
 Android : IamToast  Another Toast library for Android

Android : IamToast Another Toast library for Android Warning. toast custom view is deprecated since android 11(R) Setup allprojects { repositories

Feb 7, 2022
A library that extends the Android toast framework.
A library that extends the Android toast framework.

SuperToasts Library The SuperToasts library enhances and builds upon the Android Toast class. This library includes support for context sensitive Supe

May 13, 2022
An Android Toast replacement, similar to the one seen in the GMail app.

MessageBar An Android Toast replacement, similar to the one seen in the GMail app. Multiple messages can be posted in succession, and each message wil

Feb 16, 2022
🍞 The missing toast library for Android.
🍞 The missing toast library for Android.

Literally Toast ?? A toast library for Android. Usage: ?? Use the LitToast to get lit and show your users a proper toast. LitToast.create(context, "My

Dec 17, 2021
Custom toasts with color and icon for Android.
Custom toasts with color and icon for Android.

Dynamic Toasts A simple library to display themed toasts with icon and text on Android 2.3 (API 9) and above devices. Since v0.4.0, it uses 26.x.x sup

May 10, 2022
Android library to create customizable floating animated toasts like in Clash Royale app

FloatingToast-Android An android library to make customisable floating animated toasts Getting Started In your build.gradle dependencies { impleme

Mar 9, 2022
Toastie is a customizable Android toast library.
Toastie is a customizable Android toast library.

Toastie Getting Started Gradle Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories: Note

Apr 3, 2021
Android Custom Toast
Android Custom Toast

Super Toast Library Written Purely in Kotlin ❤ī¸ Usual Toast but with super powers!!! ?? A Fully Customised and Customisable Toast. ]( https://android-

May 2, 2021
Android Toast For RTL Applications
Android Toast For RTL Applications

RTL-Toast Android library to show Toasts in a pretty RTL way Install Add it in your root build.gradle allprojects { repositories { ... ma

Oct 19, 2021
Attractive, stylish and customizable toast library for Android.

FabToast min SDK 16 (Jelly Bean 4.1) written in Java To download the demo app for this library from Google Playstore so you can see it in action, clic

Feb 14, 2022
A tooltip/showcase library for Android re-written in Kotlin.

UglyTooltip Based on another Showcase library. Being kotlinized, customized and refactored.

Apr 27, 2022
CuteToast is an Material Design Custom Toast for Android | Custom Material Design Toast
CuteToast is an Material Design Custom Toast for Android | Custom Material Design Toast

CuteToast is an Android Custom Toast library that could be used instead of Default Toast. It does everything as Toast but with some extra spice.

Dec 14, 2021
Customizable toast message library for Android
Customizable toast message library for Android

Android Custom Toast Message (SnToast) Customizable Toast Message Library For Android Add this in your root build.gradle file allprojects { reposito

Nov 15, 2021
BiometricAuth - A simple project to show biometric authenticaation in android
BiometricAuth - A simple project to show biometric authenticaation in android

BiometricAuth a simple project to show biometric authenticaation in android link

Feb 16, 2022
In-layout notifications. Based on Toast notifications and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).
In-layout notifications. Based on Toast notifications and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).

Android AppMsg (Crouton) Library Implementation of in-layout notifications. Based on Toast notifications and article The making of Prixing #4: in-layo

May 19, 2022
An elegant context-care loading placeholder for Android
An elegant context-care loading placeholder for Android

FiftyShadesOf An elegant context-care loading placeholder for Android Usage FiftyShadesOf.with(context) .on(view1, view2, view3)

May 15, 2022
You can easily add awesome animated context menu to your app.
You can easily add awesome animated context menu to your app.

ContextMenu You can easily add awesome animated context menu to your app. Check this project on dribbble Check this project on Behance Usage: For a wo

May 17, 2022
Service exposes sensitive administration APIs to initialize and set lower level of Slurpanize infrastructure

slurpanize-baker Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its

Nov 25, 2021
Clean MVVM with eliminating the usage of context from view models by introducing hilt for DI and sealed classes for displaying Errors in views using shared flows (one time event), and Stateflow for data

Clean ViewModel with Sealed Classes Following are the purposes of this repo Showing how you can remove the need of context in ViewModels. I. By using

Apr 8, 2022