dynamic-toasts


Source link: https://github.com/pranavpandey/dynamic-toasts

Dynamic Toasts

License Build Status Download

A simple library to display themed toasts with icon and text on Android 9+ (Gingerbread or above) devices.

Since v0.4.0, it uses 26.x.x support libraries so, minimum SDK will be Android 14+ (ICS or above).
Since v2.0.0, it uses AndroidX so, first migrate your project to AndroidX.


Contents


Installation

It can be installed by adding the following dependency to your build.gradle file:

dependencies {

  // For AndroidX enabled projects.
  implementation 'com.pranavpandey.android:dynamic-toasts:2.2.1'

// For legacy projects.
  implementation 'com.pranavpandey.android:dynamic-toasts:1.3.0' 
}

Usage

It has several method to display toasts based on the requirement. Each method returns a Toast object which can be customised further.

Please call show() method to display the toast.

For complete reference, please read the documentation.

Configuration

Optional configuration to customise the toasts further like custom background color or drawable, custom text size, typeface or icon size, etc.

Various methods can be called anywhere in the app to do customisations.

DynamicToast.Config.getInstance()
  // Background color for default toast.
  .setDefaultBackgroundColor(@ColorInt int defaultBackgroundColor)
  // Tint color for default toast.
  .setDefaultTintColor(@ColorInt int defaultTintColor)
  // Background color for error toast.
  .setErrorBackgroundColor(@ColorInt int errorBackgroundColor)
  // Background color for success toast.
  .setSuccessBackgroundColor(@ColorInt int successBackgroundColor)
  // Background color for warning toast.
  .setWarningBackgroundColor(@ColorInt int warningBackgroundColor)
  // Custom icon for error toast. Pass `null` to use default icon.
  .setErrorIcon(@Nullable Drawable errorIcon)
  // Custom icon for success toast. Pass `null` to use default icon.
  .setSuccessIcon(@Nullable Drawable successIcon)
  // Custom icon for warning toast. Pass `null` to use default icon.
  .setWarningIcon(@Nullable Drawable warningIcon)
  // Disable icon for all the toasts.
  .setDisableIcon(boolean disableIcon)
  // Custom icon size in `pixels` for all the toasts.
  .setIconSize(int iconSize)
  // Custom text size in `SP` for all the toasts.
  .setTextSize(int textSize)
  // Custom text typeface for all the toasts. Pass `null` to use system typeface.
  .setTextTypeface(@Nullable Typeface textTypeface)
  // Custom background drawable for all the toasts. Pass `null` to use default background.
  .setToastBackground(@Nullable Drawable toastBackground)
  // Apply customisations.
  .apply();

Call reset() method to reset all the customisations.

// Reset customisations. DynamicToast.Config.getInstance().reset();

Default toast

Simple toast based on the vanilla Android theme for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Default toast").show();

Default toast with duration

Simple toast based on the vanilla Android theme for supplied duration.

DynamicToast.make(context, "Default toast with duration", duration).show();

Default toast with icon

Simple toast based on the vanilla Android theme with a icon for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Default toast with icon", drawable).show();

Default toast with icon and duration

Simple toast based on the vanilla Android theme with a icon for supplied duration.

DynamicToast.make(context, "Default toast with icon and duration", drawable, duration).show();

Error toast

Error toast with #F44336 background for Toast.LENGTH_SHORT duration.

DynamicToast.makeError(context, "Error toast").show();

Error toast with duration

Error toast with #F44336 background for supplied duration.

DynamicToast.makeError(context, "Error toast with duration", duration).show();

Success toast

Success toast with #4CAF50 background for Toast.LENGTH_SHORT duration.

DynamicToast.makeSuccess(context, "Success toast").show();

Success toast with duration

Success toast with #4CAF50 background for supplied duration.

DynamicToast.makeSuccess(context, "Success toast with duration", duration).show();

Warning toast

Warning toast with #FFEB3B background for Toast.LENGTH_SHORT duration.

DynamicToast.makeWarning(context, "Warning toast").show();

Warning toast with duration

Warning toast with #FFEB3B background for supplied duration.

DynamicToast.makeWarning(context, "Warning toast with duration", duration).show();

Custom toast

Custom toast based on the supplied background and tint color for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Custom toast", tintColor, backgroundColor).show();

Custom toast with duration

Custom toast based on the supplied background and tint color for supplied duration.

DynamicToast.make(context, "Custom toast with duration", tintColor, backgroundColor, duration).show();

Custom toast with icon

Custom toast based on the supplied icon, background and tint color theme for Toast.LENGTH_SHORT duration.

DynamicToast.make(context, "Custom toast with icon", drawable, tintColor, backgroundColor).show();

Custom toast with icon and duration

Custom toast based on the supplied icon, background and tint color theme for supplied duration.

DynamicToast.make(context, "Custom toast with icon and duration", drawable,

 tintColor, backgroundColor, duration).show();

Cheat sheets

Use dynamic hint to display cheat sheets for any view. All the methods are same as explained above, just replace DynamicToast with DynamicHint to create a cheat sheet.

Use DynamicHint.show(view, toast) method to display it according to the anchor view position.

Dependency

It depends on the dynamic-utils to perform various internal operations. So, its functions can also be used to perform other useful operations.


License

Copyright 2017 Pranav Pandey  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

android-parallax-recyclerview is an adapter which could be used to achive a parallax effect on RecyclerView.

android-material-drawer-template is an Android template with navigation drawer for material design.

AndroidLifecyle is a 'compatibility' version of the ActivityLifecycleCallbacks APIs that were introduced in Android 4 (API Level 14) and adding similar mechanism for Fragment.

This library was designed for creating database using ContentProvider and for reducing complexity of database tables creation.

MultiActionTextView allows to create Spannable TextView with and without under line.

PagerSlidingTabStrip is an interactive indicator to navigate between the different pages of a ViewPager. Inspired by astuetz/PagerSlidingTabStrip.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes