Android和Kotlin中的AlertDialog和CustomDialog。

In this blog, we are going to learn how to build AlertDialog and Custom dialog in android with kotlin language. you should have basic knowledge of kotlin, Activity, and Fragment.

在此博客中,我们将学习如何使用Kotlin语言在android中构建AlertDialogCustom对话框 。 您应该具有kotlinActivityFragment的基本知识。

什么是对话框? (What is a Dialog?)

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog is normally used for modal events that require users to take an action before they can proceed. for example, to confirm a user logout we can use AlertDialog, to pick a date we can use DatePickerDialog, to pick a time we can use TimePickerDialog, for downloading information we can use ProgressDialog or we can use custom dialog to contain more information by using DialogFragment class.

对话框是一个小窗口,提示用户做出决定或输入其他信息。 对话框通常用于模式事件,要求用户在执行操作之前先采取措施。 例如,要确认用户注销,我们可以使用AlertDialog ,选择一个日期,我们可以使用DatePickerDialog ,选择一个时间,我们可以使用TimePickerDialog 用于 下载信息,我们可以使用ProgressDialog或使用DialogFragment通过自定义对话框包含更多信息 类。

There are two main classes for dialogs in android. android.app.Dialog and androidx.fragment.app.DialogFragment. Dialog Class contains AlertDialog(Confirmation Dialog), DatePickerDialog, TimePickerDialog, ProgressDialog and DialogFragment class contains custom dialog.

android中有两个主要的对话框类。 android.app.Dialogandroidx.fragment.app.DialogFragmentDialog类包含AlertDialog(Confirmation Dialog)DatePickerDialogTimePickerDialogProgressDialogDialogFragment类包含custom dialog

使用对话框的最佳实践 (Best Practice to use Dialog)

  1. Avoid Scrollable Dialog.

    避免滚动对话框。
  2. Avoid Multiple dialogs on a single screen.

    避免在单个屏幕上出现多个对话框。
  3. Do not open Dialog automatically.

    不要自动打开对话框。
  4. Do not create confusion user action.

    不要造成混乱的用户操作。

Let's see what is AlertDialog

让我们看看什么是AlertDialog

警报对话框 (AlertDialog)

The AlertDialog class allows us to build a variety of dialog designs. As shown in the figure, there are three regions of an alert dialog as title, content area, and action buttons. these are fixed by the android. And this window is resizeable with the content.

AlertDialog类使我们可以构建各种对话框设计。 如图所示,警报对话框的三个区域分别是title content areaaction buttons 。 这

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值