Change Android Toast background color

You must have seen that by default we get a dark greyish kind of background color for a toast message that is displayed in Android Activity Screen (may vary depending upon what flavor of Android OS you are using). If you want to develop a custom Toast message with a color combination that suits your app design then we can do it programmatically using setBackgroundResource() provided by the Toast Class. Let's see an example, we will change the background color to Yellow and the toast text color to white,

Custom toast color
Custom toast color

We need to create a drawable XML file to achieve this, we will create toast_drawable.xml and store it in the any of the drawable folders under res. We will add a solid tag to set the background color.

File : toast_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="" >

    <solid android:color="#ffff00" />

File :
package com.code2care.toast;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

    protected void onCreate(Bundle savedInstanceState) {

    public void displayToast(View view) {
    	Toast toast = Toast.makeText(getApplicationContext(),
    	        "Custom toast background color",
    	View toastView = toast.getView();
Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap