But we can use an external library to make a customize Toast messages. In this post, I'll present the way how to implements Crouton library, it can make your messages become more flexible.
1. Download and import library in Eclipse
- Download Crouton at it's Github page.
Crouton is being built using gradle. This means that the source directories are different to the default Eclipse source paths, so we must fix it by following these steps.
- Unzipped the file and copied out the library folder.
- Open eclipse and import the library into the workspace (The name changes to "main").
- Drag and drop the "de" folder from "java" to "src" folder in "main" project:
- Create a "libs" folder in your "main" project and put android-support-v4.jar in it:
- Clean project, now errors in our library have disappeared.
Note: Okey, by other way, you can download lastest version of Crouton jar file at Maven Center and put it in your libs folder of your project. So you can ignore all above steps.
2. Starting a new project using Crouton library
After done creating project, remember making preference between it and "main" project.
Creating layout for activity (activity_crouton.xml):
- Strings use in project (strings.xml):
- A customize layout use for Toast message later:
Coding in CroutonActivity
- Displaying 3 basic styles of Crouton (INFO, ALERT, CONFIRM) method:- Displaying customize style of Crouton method:
- Customizing Crouton style with a layout method:
Full CroutonActivity.java code:
Run the application, we'll have some results like this:
Reference:
- Library in Github page: https://github.com/keyboardsurfer/Crouton- Author Home page: http://marie-schweiz.de/
(Sorry for having ads)