李成笔记网

专注域名、站长SEO知识分享与实战技巧

零基础学鸿蒙编程-常用工具_Toast

什么是Toast

Toast是用来短时显示提示信息并自动消失的UI控件. 默认一般显示在屏幕的下方.

基础样例

  1. 显示默认toast
  • 效果图:
  • 代码:
new ToastDialog(getContext()).setText("花生皮编程,哈哈").show();
  1. 在顶部显示toast
  • 效果图:
  • 代码:
ToastDialog dialog = new ToastDialog(getContext());
dialog.setText("花生皮编程,哈哈");
dialog.setAlignment(LayoutAlignment.TOP);
dialog.show();
  1. 居中显示toast
  • 效果图:
  • 代码:
ToastDialog dialog = new ToastDialog(getContext());
dialog.setText("花生皮编程,哈哈");
dialog.setAlignment(LayoutAlignment.CENTER);
dialog.show();

完整源代码

https://gitee.com/hspbc/harmonyos_demos/tree/master/toastDemo

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言