Toast 自定义位置和带图

1.自定义位置

Toast t = Toast.makeText(Reg_FillContent_Activity.this, "用户已存在!", Toast.LENGTH_SHORT);
    t.setGravity(Gravity.CENTER, 0,0 );  //居中
    t.show();

2.带图

Toast toast = Toast.makeText(Reg_FillContent_Activity.this, "带图的Toast!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0,0 ); //居中
LinearLayout toastView = (LinearLayout) toast.getView();
ImageView imageCodeProject = new ImageView(getApplicationContext());
imageCodeProject.setImageResource(R.drawable.icon);
toastView.addView(imageCodeProject, 0);
toast.show();


 

你可能感兴趣的:(toast,位置和带图)