I need to access the created Toast XML code that has been displayed at runtime for testing purposes. Is there any way to do that?
            Asked
            
        
        
            Active
            
        
            Viewed 70 times
        
    2 Answers
0
            
            
        Maybe you should use Toast messages programmatically, like this in Java:
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
And in Kotlin:
val text = "Hello toast!"
val duration = Toast.LENGTH_SHORT
val toast = Toast.makeText(applicationContext, text, duration)
toast.show()
I think u can use this like a function to testing.
Also, if you want to know about Toast message much more, please follow a link to Android Developers Blog: https://developer.android.com/guide/topics/ui/notifiers/toasts#kotlin
 
    
    
        Max Shwed
        
- 232
- 2
- 10
- 
                    Thank you so much but i need to access the created xml code that has been created during the run time so that it can appears when doing automation testing! – wageeh Jan 16 '20 at 14:05
0
            
            
        Toast toast = Toast.makeText(getApplicationContext(),  "Hello toast!", Toast.LENGTH_SHORT);
toast.show();
View toastView = toast.getView();
 
    
    
        Rabiun Islam
        
- 75
- 5
- 
                    Thank you so mush for your help but i still need more clarification ,, how can i access the xml code of that toast? – wageeh Jan 16 '20 at 14:04
- 
                    if you want to access any view reference of the toast view, then it would be better to go for custom toast . See this link https://stackoverflow.com/questions/11288475/custom-toast-on-android-a-simple-example – Rabiun Islam Jan 22 '20 at 08:05
