-1

I have a toast which shows text as centered align and i want to make it left align how can it be done. The code for generation of toast is as follows.

Toast test;
String final_status = titles[status_index];
String final_equipment = EquipmentNamePartial[equipment_index];
test = Toast.makeText(SalesBar.this, "Status: " + final_status + '\n'
         + " Equipment: " + final_equipment + '\n'
         + " Duration: " + duration_value + " hours", Toast.LENGTH_SHORT);
test.setGravity(Gravity.TOP|Gravity.LEFT, xx, yy);
test.show();
CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
Fahad Abid Janjua
  • 1,024
  • 3
  • 14
  • 35

3 Answers3

2

Create Custom Toast Message.

TextView textview = new TextView(context);
textview.setText(text);
textview.setBackgroundColor(Color.WHITE);
textview.setTextColor(Color.BLACK);
textview.setPadding(10,10,10,10);
Toast toast = new Toast(context);
toast.setView(textview);
toast.setDuration(Toast.LENGTH_LONG);
toast.setGravity(Gravity.LEFT, 0, 0);
toast.show();
Chirag
  • 56,621
  • 29
  • 151
  • 198
1

You should create a View and use Toast.setView. The simplest case is to create a TextView and set it's gravity

yoah
  • 7,180
  • 2
  • 30
  • 30
1

You can create Toast with custom layout:

Toast toast = new Toast(context);
toast.setView(toastRoot);
toast.show();

Here is some samples: http://blog.webagesolutions.com/archives/161, http://www.helloandroid.com/tutorials/how-customize-toasts

amukhachov
  • 5,822
  • 1
  • 41
  • 60