toast可以设置自定义的view和显示位置。下面是一个简单的例子,复杂些的就是改变其布局文件就可以了。

/**
 * @author BMR
 * @ClassName: ToastWithTwoText
 * @Description: TODO:
 * @date 2015/12/22 14:24
 */
public class ToastWithTwoText {
    private static ToastWithTwoText toastWithTwoText;

    private Toast toast;
    private Context mContext;

    private ToastWithTwoText(Context context) {
        this.mContext = context;
    }

    public static ToastWithTwoText createToastConfig(Context context) {
        if (toastWithTwoText == null) {
            toastWithTwoText = new ToastWithTwoText(context);
        }
        return toastWithTwoText;
    }

    /**
     * 显示Toast
     *
     * @param tvStrOne
     * @param tvStrTwo
     */

    public void ToastShow(String tvStrOne, String tvStrTwo) {
        View layout = LayoutInflater.from(mContext).inflate(R.layout.layout_toast_with_two_text, null);
        TextView tvOne = (TextView) layout.findViewById(R.id.tv_text_one);
        TextView tvTwo = (TextView) layout.findViewById(R.id.tv_text_two);
        tvOne.setText(tvStrOne);
        tvTwo.setText(tvStrTwo);
        toast = new Toast(mContext);
        toast.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        toast.show();
    }

    public void ToastShow(int idStrOne, int idStrTwo) {
        ToastShow(mContext.getString(idStrOne), mContext.getString(idStrTwo));
    }

}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2021-07-11
相关资源
相似解决方案