private void showMyToast(){
LayoutInflater inflater =this.getLayoutInflater();
View view = inflater.inflate(android.R.layout.simple_list_item_2,null);
view.setBackgroundColor(Color.RED);
TextView text1=(TextView) view.findViewById(android.R.id.text1);
text1.setText("Toast 1");
text1.setTextColor(Color.WHITE);
TextView text2=(TextView) view.findViewById(android.R.id.text2);
text2.setText("Toast 2");
text2.setTextColor(Color.YELLOW);
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL,0,0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.show();
}
运行结果如图所示: