Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toast background changing to match Activity's Theme

Tags:

I have created a custom theme for my activities that they all use. In the theme, I set android:background, and this happens to cause any dialog or toast message to look very strange.

How do I prevent toast and the other dialogs from absorbing the theme's properties?

like image 847
Malfist Avatar asked Aug 11 '11 02:08

Malfist


1 Answers

You can easily create custom toast by the following code:

Toast toast = Toast.makeText(context, resTxtId, Toast.LENGTH_LONG); View view = toast.getView(); view.setBackgroundResource(R.drawable.custom_bkg); TextView text = (TextView) view.findViewById(android.R.id.message); /*here you can do anything with text*/ toast.show(); 

Or you can instantiate a completely custom toast:

Toast toast = new Toast(context); toast.setDuration(Toast.LENGTH_LONG);  LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  View view = inflater.inflate(R.layout.custom_layout, null); toast.setView(view); toast.show(); 

Dialog customizing is a more complex routine. But there is similar workaround.

like image 111
Dmitry Avatar answered Oct 21 '22 15:10

Dmitry