[embedyt] https://www.youtube.com/watch?v=3AvCmRrNxvk[/embedyt]
Links & Dependenciesactivity_main.xmlMainActivity.java
Library on GitHub with dependency + instructions:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.codinginflow.alerterexample.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="showAlerter" android:text="Show Alerter" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
package com.codinginflow.alerterexample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import com.tapadoo.alerter.Alerter; import com.tapadoo.alerter.OnHideAlertListener; import com.tapadoo.alerter.OnShowAlertListener; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void showAlerter(View v) { Alerter.create(this) .setTitle("Alert Title") .setText("Alert Text") .setIcon(R.drawable.ic_android_black_24dp) .setBackgroundColorRes(R.color.colorAccent) .setDuration(5000) .enableSwipeToDismiss() //seems to not work well with OnClickListener .enableProgress(true) .setProgressColorRes(R.color.colorPrimary) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //do something when Alerter message was clicked } }) .setOnShowListener(new OnShowAlertListener() { @Override public void onShow() { //do something when Alerter message shows } }) .setOnHideListener(new OnHideAlertListener() { @Override public void onHide() { //do something when Alerter message hides } }) .show(); } }