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,它将文本显示为居中对齐,我想让它保持对齐,如何才能完成。生成吐司的代码如下。
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();
3 个解决方案
#1
2
Create Custom Toast Message.
创建自定义Toast消息。
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();
#2
1
You should create a View and use Toast.setView. The simplest case is to create a TextView and set it's gravity
您应该创建一个View并使用Toast.setView。最简单的情况是创建一个TextView并设置它的重力
#3
1
You can create Toast
with custom layout:
您可以使用自定义布局创建Toast:
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
以下是一些示例:http://blog.webagesolutions.com/archives/161,http://www.helloandroid.com/tutorials/how-customize-toasts
#1
2
Create Custom Toast Message.
创建自定义Toast消息。
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();
#2
1
You should create a View and use Toast.setView. The simplest case is to create a TextView and set it's gravity
您应该创建一个View并使用Toast.setView。最简单的情况是创建一个TextView并设置它的重力
#3
1
You can create Toast
with custom layout:
您可以使用自定义布局创建Toast:
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
以下是一些示例:http://blog.webagesolutions.com/archives/161,http://www.helloandroid.com/tutorials/how-customize-toasts