Accepted answer is correct but in my case the toast blink(show & hide) can be noticed..
I got a solution where Toast is not blinking and you can customise the Toast as well.
Lets begin,
1) Create a class Named LongToast.
class LongToast {
private LongToast() {}
static void makeLongToast(Context context,String text, long durationInMillis)
{
final Toast toastMessage = new Toast(context);
//Creating TextView.
TextView textView = new TextView(context);
//Setting up Text Color.
textView.setTextColor(Color.parseColor("#fafafa"));
//Setting up Text Size.
textView.setTextSize(17);
//Setting up Toast Message Text.
textView.setText(text);
//Add padding to Toast message.
textView.setPadding(20, 20, 20, 23);
//Add Gravity TextView.
textView.setGravity(Gravity.CENTER);
//Adding TextView into Toast.
toastMessage.setView(textView);
//Access toast message as View.
View toastView = toastMessage.getView();
//Set Custom Background on Toast.
toastView.setBackgroundResource(R.drawable.test);
new CountDownTimer(durationInMillis, 1000)
{
public void onTick(long millisUntilFinished)
{
toastMessage.show();
}
public void onFinish()
{
toastMessage.cancel();
}
}.start();
}
}
2) Create a drawable xml for customising the Toast.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#009973"/>
<corners android:radius="20dp" />
<stroke
android:width="4dp"
android:color="#01ffc0"
/>
</shape>
you can customise the toast as per your need.
3) Finally Calling Toast.
LongToast.makeLongToast(this,"whatever you want",10000);//duration in seconds
ref : click here to check
Thanks!!.