Android 自定义Toast

忘是亡心i 2022-06-03 02:41 408阅读 0赞

自己设置Toast的显示位置、背景颜色等等,封装了一个方法,在程序中可以直接掉用。。

  1. public static void showTextToast(Context context, String msg) {
  2. if (context == null) {
  3. return;
  4. }
  5. if (toast == null) {
  6. toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
  7. toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
  8. View view = toast.getView();
  9. view.setBackgroundResource(android.R.color.holo_blue_dark);
  10. toast.setView(view);
  11. } else {
  12. toast.setText(msg);
  13. }
  14. toast.show();
  15. }

发表评论

表情:
评论列表 (有 0 条评论,408人围观)

还没有评论,来说两句吧...

相关阅读