文档开发者中心
我的

求助,鸿蒙中有类似Alert的组件吗?点击确定或者取消提示框才消失

求助,鸿蒙中有类似Alert的组件吗?点击确定或者取消提示框才消失,是需要使用ToastDialog自己封装吗?有大神封装过吗?求助求助

点赞
收藏
回复
4
分享
举报
浏览555 发布于2021-04-26 02:40未知归属地
全部评论
最多点赞
最新发布
最早发布

开发者你好,请参考:

/**
 * 弹出对话框
 * @param context 上下文
 * @param contentText 对话框内容
 * @param titleText 对话框标题
 * @param leftButtonText 对话框左边按钮内容
 * @param rightButtonText 对话框右边按钮内容
 */
public static void showDialog(Context context,String contentText, String titleText,String leftButtonText,String rightButtonText) {
    CommonDialog commonDialog = new CommonDialog(context);
    Component dialogLayout = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_dialog_layout, null, false);
    Text titleView = (Text)dialogLayout.findComponentById(ResourceTable.Id_dialog_title_view);
    Button confirmButton = (Button)dialogLayout.findComponentById(ResourceTable.Id_dialog_confirm_button);
    Button cancelmButton = (Button)dialogLayout.findComponentById(ResourceTable.Id_dialog_cancel_button);
    Text contentDialogText = (Text) dialogLayout.findComponentById(ResourceTable.Id_dialog_content_view);
    titleView.setText(titleText);
    confirmButton.setText(leftButtonText);
    cancelmButton.setText(rightButtonText);
    contentDialogText.setText(contentText);
    commonDialog.setContentCustomComponent(dialogLayout);
    confirmButton.setClickedListener(new Component.ClickedListener() {
        @Override
        public void onClick(Component component) {

        }
    });
    cancelmButton.setClickedListener(new Component.ClickedListener() {
        @Override
        public void onClick(Component component) {
            commonDialog.destroy();
        }
    });
    commonDialog.show();
}
2
2楼回复于2021-04-26 08:01 未知归属地
  • 鸿蒙开发者奣

    好的,谢谢,我去试一试

    2021-04-26 08:20 未知归属地
  • 鸿蒙开发者奣

    您好,xml的布局代码可以发一份吗?我不太清楚这个布局是什么样的

    2021-04-27 00:55 未知归属地

欢迎小伙伴们进来帮帮楼主~~~~~~

1楼回复于2021-04-26 03:45 未知归属地
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。