[embedyt] https://www.youtube.com/watch?v=fq8TDVqpmZ0[/embedyt]
Links & Dependenciesactivity_main.xmlMainActivity.javastyles.xml
Library on GitHub with installation 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.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>
package com.codinginflow.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(); } }
<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>