-2

I don't know how it's called, but it's a small, gray, transparent box which shows information. I want to create it for my app, and write different information in it.

Kazhiunea
  • 11
  • 3

2 Answers2

1
Toast.makeText(this, "your message", Toast.LENGTH_SHORT).show();

Here this is context like in activity you can pass YourActivity.this or in Fragment class you can pass getActivity().

Toast.LENGTH_SHORT or Toast.LENGTH_LONG are two duration which you can use to show Toast.

toast message

Update :

Positioning your Toast

A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.

For example, if you decide that the toast should appear in the top-left corner, you can set the gravity like this:

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0); If you want to nudge the position to the right, increase the value of the second parameter. To nudge it down, increase the value of the last parameter.

Reference

Create custom Toast with your color and layout like

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.your_custom_layout, null);
toast.setView(view);
toast.show();

One textview you can put inside the layout file and give the background and textcolor as you want.

Also you can do the following which won't need the extra custom layout file :

Toast toast = Toast.makeText(context, R.string.string_message_id, Toast.LENGTH_LONG);
View view = toast.getView();
view.setBackgroundResource(R.drawable.custom_backgrround);
TextView text = (TextView) view.findViewById(android.R.id.message);
/*Here you can do anything with above textview like text.setTextColor(Color.parseColor("#000000"));*/
toast.show();

Reference

If you don't want do all this stuff here is library for fancy toast. Which allow you custom toast with many inbuilt themes.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
0

Presumably, you are referring to a Toast.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491