arnavs-0 / Toaster

Material Design Style Toasts, for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Toaster

Known Vulnerabilities Hits

Material Design Style Toasts, for Android

Screenshots

Prerequisites

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Dependency

Add this to your module's build.gradle file (make sure the version matches the JitPack badge above):

dependencies {
	...
	implementation 'com.github.arnavs-0:Toaster:1.0.1'
}

Usage

Each method always returns a Toast object, so you can customize the Toast. Don't Forget to use the show(); method!

To display a success Toast:

Toaster.makeText(this, "Success", Toaster.LENGTH_SHORT, Toaster.SUCCESS).show();

To display an error Toast:

Toaster.makeText(this, "Error", Toaster.LENGTH_SHORT, Toaster.ERROR).show();

To display a warning Toast:

Toaster.makeText(this, "Warning", Toaster.LENGTH_SHORT, Toaster.WARNING).show();

To display an info Toast:

Toaster.makeText(this, "Info", Toaster.LENGTH_SHORT, Toaster.INFO).show();

To display a normal Toast:

Toaster.makeText(this, "Success", Toaster.LENGTH_SHORT, Toaster.DEFAULT).show();

Advanced

You can also make custom toasts as well with a custom background and icon. You need to have a drawable that follows these standards:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!--Shadow-->
            <solid android:color="#7B1FA2" />
            <corners android:radius="5dp" />
        </shape>
    </item>

    <item android:bottom="4px">
        <shape android:shape="rectangle">
            <solid android:color="#C2185B" />
            <corners android:radius="5dp" />
        </shape>
    </item>
</layer-list>

Custom.xml

The icon must also be a drawable as well.

icon.xml

How to add custom icon and background:

 Toaster.makeTextCustom(this, "Custom with Icon", Toaster.LENGTH_SHORT, 
         this.getDrawable(R.drawable.custom), this.getDrawable(R.drawable.ic_baseline_android_24)).show();

How to add custom background and custom text color: (Text must be in hex format)

Toaster.makeTextBackground(this, "Custom No Icon", Toaster.LENGTH_SHORT,
                    this.getDrawable(R.drawable.custom), "#000000").show();

Have a question or issue? Open a issue

About

Material Design Style Toasts, for Android

License:GNU General Public License v3.0


Languages

Language:Java 100.0%