Development issue/problem:

I display the toast message as a result of the if declaration with the following code :

Toast.makeText(getBaseContext(), Enter the Price, Toast.LENGTH_SHORT).show() ;

It appears as a white text on a white background, so unreadable! My question is: how can I change the colour of the toast text?

How can I solve this problem?

Solution 1:

You can make your own kind of toast according to your needs. See Making a custom toast at

Solution 2:

You can do this very easily without creating your own layout by using the standard Toast:

ToastToast = Toast.makeText(dit, resId, Toast.LENGTH_SHORT);
TextView v = (TextView) toast.getView().findViewById(;
v.setTextColor(Color.RED); ;

The default presentation of the Toast view is in the Android SDK :


Solution 3:

You can make your own toast

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(

ImageView image = (ImageView) layout.findViewById(;
TextView text = (TextView) layout.findViewById(;
text.setText(Hello! This is your toast!)

Toast toast = new Toast(getApplicationContext()) ;
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0) ;
toast.setDuration(Toast.LENGTH_LONG) ;
toast.setView(layout) ; ;


Solution 4:

The easiest way to change the background colour of the toast and the background colour of the toast text:

TextView text;
toast.makeText(this, resId, Toast.LENGTH_SHORT);
view = toast.getView();
text = (TextView) view.findViewById(;
view.setBackgroundResource(R.color.white); ;

Solution No 5:

You can also use SpannableString. It can also color parts of a rope.

SpannableString spanableString = new SpannableString(This is red text);
new ForegroundColorSpan(getResources().getColor(android.R.color.holo_red_light))),
Toast.makeText(this, SpannableString, Toast.LENGTH_SHORT).show() ;

Solution No 6:

Try the Toasty Library. It is very easy to use –

Android: How to set the colour of a Toast’s text –

Solution No 7:

You can try this if you don’t want to use custom libraries.

Toast=Toast.makeText(getApplicationContext(),This is extended toast,Toast.LENGTH_LONG);
view textview1=(TextView)view.findViewById( ;
view1.setTextColor(Color.YELLOW) ;
view.setBackgroundResource(R.color.colorPrimary) ; ;

Solution No 8:

Here is an example in Kotlin that shows how to change the background colour of the toast and the colour of the text:

val toast = Toast.makeText(context, text, Toast.LENGTH_SHORT)toast.view.background.setColorFilter(ContextCompatible.getColor(context,R.color.white), PorterDuff.Mode.SRC_IN)fall textView = toast.view.findViewById( as TextViewtextView.setTextColor(ContextCompat.getColor(context,

Good luck!

android toast default background color,toast background,how to change toast text size in android,android toast style,custom toast in android,toast gravity,toast getview deprecated,android toast font color,android toast bold text,android toast theme,how to set toast size in android

You May Also Like

Calling Android Native Code in Flutter

In this tutorial we make a small beat function that calls the…

How to Protect Yourself from Increasing Malware Attacks During the Pandemic

It’s very sad that the internet is not a safe place. Attackers…

Recover Deleted or Lost Data From Tecno L8/L8 Plus/L8 Lite

Board of Experts : The best way to recover lost data on…

10 Best Torrent Downloader Software

Finding a stream you like is no longer a problem these days.…