How can I change default toast message color and background color in android?

后端 未结 15 869
执念已碎
执念已碎 2020-12-23 17:12

I want to create a toast message with background color is white and message color is black. My toast message is:

Toast.makeText(Logpage.this, \"Please Give          


        
15条回答
  •  我在风中等你
    2020-12-23 17:57

    Create a layout file toast.xml as to how your toast should look as below:

    
    
    
        
    
    
    

    To show the toast in the java file put the below code:

    public void showCustomAlert()
        {         
            Context context = getApplicationContext();
            // Create layout inflator object to inflate toast.xml file
            LayoutInflater inflater = getLayoutInflater();
    
            // Call toast.xml file for toast layout 
            View toastView = inflater.inflate(R.layout.toast, null);
    
            Toast toast = new Toast(context);
            toastView.setView(toast);
    
            // Set layout to toast 
            toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,
                    0, 0);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();         
        }
    

提交回复
热议问题