今天学习了自定义Toast。
主要代码为:
private void midToast(String str, int showTime) { Toast toast = Toast.makeText(mContext, str, showTime); toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM , 0, 0); //设置显示位置 LinearLayout layout = (LinearLayout) toast.getView(); layout.setBackgroundColor(Color.BLUE); ImageView image = new ImageView(this); image.setImageResource(R.mipmap.ic_icon_qitao); layout.addView(image, 0); TextView v = (TextView) toast.getView().findViewById(android.R.id.message); v.setTextColor(Color.YELLOW); //设置字体颜色 toast.show(); }