LayoutInflater inflater = LayoutInflater
.from(getApplicationContext());
View view = inflater.inflate(R.layout.my_toast,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView textView = (TextView) view.findViewById(R.id.text);
SpannableString ss = new SpannableString("掃描成功");
ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 4,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
mytoast.xml
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10dp" >
android:layout_marginTop="800dip"
android:textSize="25dip"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="50dip"
android:textColor="@color/black" />