Full project with source code of StyleableToast library, with which we can easily create toasts with customized attributes like background color, text color, borders, icons and more
build.gradle
dependencies {
implementation 'io.github.muddz:styleabletoast:2.4.0'
}
activity_main.xml
<?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="tech.codingpoint.styleabletoastexample.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showToast"
android:text="Show Toast"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
package tech.codingpoint.styleabletoastexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.muddzdev.styleabletoastlibrary.StyleableToast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void showToast(View v) {
StyleableToast.makeText(this, "Hello World!", R.style.exampleToast).show();
}
}
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="exampleToast">
<item name="colorBackground">#94ffab</item>
<item name="textColor">#000</item>
<item name="iconLeft">@drawable/ic_android</item>
<item name="strokeColor">#000</item>
<item name="strokeWidth">3dp</item>
<item name="length">LONG</item>
<item name="cornerRadius">3dp</item>
</style>
</resources>