Toasty Metho
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }//Paste gradle
}
}
dependencies (implementation 'com.github.GrenderG:Toasty:1.4.2') Paste Gradle (Module App)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:onClick="ShowToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_error"
android:text="SHOW ERROR TOAST"/>
<Button
android:onClick="ShowToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_success"
android:text="SHOW Success TOAST"/>
<Button
android:onClick="ShowToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_info"
android:text="SHOW INFORMATION TOAST"/>
<Button
android:onClick="ShowToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_warning"
android:text="SHOW Warning TOAST"/>
<Button
android:onClick="ShowToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_warning"
android:text="SHOW Warning TOAST"/>
<Button
android:onClick="ShowToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_normal"
android:text="SHOW NORMAL TOAST"/>
</LinearLayout>
Main .java
package com.patelada.toaststyle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import es.dmoral.toasty.Toasty;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ShowToast(View view)
{
switch (view.getId())
{
case R.id.btn_error:
Toasty.error(this,"ERROR TOAST ", Toast.LENGTH_LONG).show();
break;
case R.id.btn_success:
Toasty.success(this,"SUCCESS TOAST ", Toast.LENGTH_LONG).show();
break;
case R.id.btn_info:
Toasty.info(this,"INFORMATION TOAST ", Toast.LENGTH_LONG).show();
break;
case R.id.btn_warning:
Toasty.warning(this,"WARNING TOAST ", Toast.LENGTH_LONG).show();
break;
case R.id.btn_normal:
Toasty.normal(this,"NORMAL TOAST ", Toast.LENGTH_LONG, ContextCompat.getDrawable(this,R.drawable.ic_baseline_cloud_off_24)).show();
break;
}
}
}
0 Comments