自定义Toast

作者:追风剑情 发布于:2016-8-3 11:11 分类:Android

  1. public void showToast()
  2. {
  3. String msg = "To the bride and groom!";
  4. int duration = Toast.LENGTH_LONG;
  5. Toast toast = Toast.makeText(this, msg, duration);
  6. int offsetX = 0;
  7. int offsetY = 0;
  8. //设置位置
  9. toast.setGravity(Gravity.BOTTOM, offsetX, offsetY);
  10. //设置自定义视图
  11. LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  12. View view = inflater.inflate(R.layout.toast_view, null);
  13. toast.setView(view);
  14. //显示
  15. toast.show();
  16. }

运行测试

111111.png

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号