Mega Code Archive

 
Categories / Android / UI
 

Toast with TextView

import android.content.Context; import android.graphics.Color; import android.graphics.Typeface; import android.view.Gravity; import android.widget.TextView; import android.widget.Toast;  class ToastForAPP {     public static void toastNow(String message,Context context)     {         Toast toast = Toast.makeText(context,message, Toast.LENGTH_LONG);         toast.setGravity(Gravity.CENTER, toast.getXOffset() / 2, toast.getYOffset() / 2);         TextView textView = new TextView(context);         textView.setBackgroundColor(Color.DKGRAY);         textView.setTextColor(Color.WHITE);         textView.setTextSize(30);         Typeface typeface = Typeface.create("serif", Typeface.BOLD);         textView.setTypeface(typeface);         textView.setPadding(10, 10, 10, 10);         textView.setText(message);         toast.setView(textView);         toast.show();     } }