对警报线程池的警报线程_您可能对警报对话框不了解的地方

2023-11-07 00:59

本文主要是介绍对警报线程池的警报线程_您可能对警报对话框不了解的地方,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

对警报线程池的警报线程

This seemingly simple UI element has a lot of hidden features. If you have ever developed an application, you probably have used it.

这个看似简单的UI元素具有许多隐藏功能。 如果您曾经开发过应用程序,则可能已经使用过。

An AlertDialog’s main function is to notify users of something that is going to happen that requires their immediate attention and an action to be made on their end. The uses of an AlertDialog are numerous and could range from:

AlertDialog的主要功能是通知用户即将发生的事情,这些事情需要他们的立即注意并最终采取措施。 AlertDialog的用途很多,范围可能是:

  • Ask the user to grant permission for your application to do something (location)

    要求用户授予您的应用程序执行某项操作的权限(位置)
  • Alert the user to an action that is about to take place (remove photo)

    提醒用户即将执行的操作(删除照片)
  • Notify the user of what is going on (feature not available)

    通知用户正在发生的事情(功能不可用)

What this article will not cover is the basic use cases and construction of an AlertDialog, but it will cover some more advanced uses and caveats of this UI element.

本文将不介绍AlertDialog的基本用例和构造,但将介绍此UI元素的一些更高级的用法和注意事项。

For this article, I will be showing examples written in Kotlin.

对于本文,我将展示用Kotlin编写的示例。

AlertDialog标题的长度 (Length of AlertDialog’s Title)

Setting the title on an AlertDialog is easy. Using the following method,

在AlertDialog上设置标题很容易。 使用以下方法,

builder.setTitle(title), //where title is a CharSequence. 
setTitle
setTitle

What is not apparent from the code, is that the dialog’s title is limited to only two lines. Meaning, that if you write a long title, it will be truncated and you will see three dots (…) being displayed signifying the sentence is longer than it appears.

从代码中看不出来的是,对话框的标题仅限于两行。 意思是,如果您写了一个长标题,它将被截断,并且您将看到显示三个点(…),表示该句子的长度超过了它的显示长度。

Image for post
Truncated Title
标题被截断

But what If we needed more room for our title? We can use the method setCustomTitle which receives a View as a parameter.

但是,如果我们需要更多的标题空间呢? 我们可以使用setCustomTitle方法,该方法接收一个View作为参数。

setCustomTitle
setCustomTitle

Using the above, we can easily create a TextView and style it to our liking to get the desired result.

使用上面的代码,我们可以轻松地创建一个TextView并根据自己的喜好对其进行样式设置,以获得所需的结果。

An AlertDialog with a custom title
具有自定义标题的AlertDialog
Image for post
Our Result
我们的结果

中立按钮 (The Neutral Button)

While you may be familiar with the approve or reject buttons associated with the AlertDialog, there is also one other type of button available. That button is the NeutralButton. What is special about this button is that it signals to the user that if he/she makes this choice, nothing will be affected.

尽管您可能熟悉与AlertDialog相关的批准或拒绝按钮,但还有另一种类型的按钮可用。 该按钮是NeutralButton 。 此按钮的特殊之处在于,它向用户发出信号,如果他/她做出了此选择,则不会受到任何影响。

Neutral Button
中立按钮

If you take another look at the screenshot above, you can see that the button with the Dismiss text is a neutral button.

如果您再看一下上面的屏幕截图,您会看到带有“关闭”文本的按钮是一个中性按钮。

物品或讯息 (Items Or Message)

After setting the title, we can set the message of our alert dialog. Again, what if we wanted the user to select something in our alert dialog (out of a list)? For that, we can use the setItems method:

设置标题后,我们可以设置警报对话框的消息。 同样,如果我们希望用户在警报对话框中(从列表中)选择某些内容,该怎么办? 为此,我们可以使用setItems方法:

setItems
setItems

Or we can use the setSingleChoiceItems method:

或者我们可以使用setSingleChoiceItems方法:

Here, we come to a fork in the road, because we will have to choose what is more important to us: a list of items or the alert dialog’s message. We can’t have both. To quote the documentation:

在这里,我们走上了一条路,因为我们必须选择对我们更重要的内容:项目列表或警报对话框的消息。 我们不能两者兼得。 引用文档:

…Because the list appears in the dialog’s content area, the dialog cannot show both a message and a list…

…因为该列表出现在对话框的内容区域中,所以该对话框无法同时显示消息和列表…

When using an items list, it is a good idea to use an adapter to handle the interaction and management of our list of items. Below is a simple demonstration of just how to achieve that.

使用项目列表时,最好使用适配器来处理项目列表的交互和管理。 以下是如何实现该目标的简单演示。

MainActivity.kt
MainActivity.kt
AlertDialogListAdapter.kt
AlertDialogListAdapter.kt
list_item.xml
list_item.xml
Image for post
List of items in AlertDialog
AlertDialog中的项目列表

If you don’t want to deal with an adapter, you can use the setSingleChoiceItems method like so:

如果您不想使用适配器,则可以使用setSingleChoiceItems方法,如下所示:

Using SetSingleChoiceItems
使用SetSingleChoiceItems

And you’ll get the following:

您将获得以下信息:

Image for post

图像警报 (Image Alert)

What if we wanted to have a message and an image in our AlertDialog? We can achieve that by using the setView method:

如果我们想在AlertDialog中显示消息和图像怎么办? 我们可以通过使用setView方法来实现:

setView
setView
MainActivity.kt
MainActivity.kt
custom_view.xml
custom_view.xml
Image for post
Our Custom View
我们的自定义视图

🙌 In fact, you may have noticed that even for the previous problem, we can use a custom view that has a listview and a textview to handle the scenario of a message and a list of items.

🙌实际上,您可能已经注意到,即使对于先前的问题,我们也可以使用具有listview和textview的自定义视图来处理消息和项目列表的情况。

Those are just some of the more allusive possibilities you have with the AlertDialog. If you have more examples like this, feel free to share them in the comments.

这些只是您使用AlertDialog所具有的更多暗示性可能性。 如果您有更多类似的示例,请随时在评论中分享。

You can see all the examples shown in this article in an application I created at this GitHub repository.

您可以在我在GitHub存储库中创建的应用程序中看到本文显示的所有示例。

翻译自: https://proandroiddev.com/what-you-might-not-know-about-the-alertdialog-2bdc55f3d907

对警报线程池的警报线程


http://www.taodudu.cc/news/show-8172790.html

相关文章:

  • 7-9 红色警报 (25分)
  • PTA-L2-013 红色警报 (25分)
  • Qt去除未使用变量警报
  • 今天您手机上的“总统警报”弹出窗口是什么?
  • 51单片机警报装置
  • SQL Server代理警报
  • 智慧家——火灾警报
  • 美的冲刺港股:年营收3457亿 不缺钱,但资本运作频频
  • 07胡润IT富豪榜发布:李彦宏成IT首富
  • 设置 google 搜索引擎 不跳转 对应 地区语言页面
  • 基本过程: 小区搜索
  • 地区选择控件的展示和使用
  • 各搜索引擎高级搜索备忘
  • Google搜索指定地区,不跳转
  • elementUI的el-cascader实现省市区搜索
  • vue3实现模糊搜索功能
  • 百度地图---poi地区搜索
  • 百度的地区搜索是如何实现的?
  • C语言枚举打桩
  • 单元测试PowerMockito打桩失效
  • linux库打桩
  • go stub打桩测试
  • 【流量分析】Godzilla分析
  • (纪中)2416. Berry Picking【数学】
  • 2020寒假【gmoj2416】【Berry Picking】
  • 牛客练习赛62(基于官方题解的补题 A ~ D)
  • CQOI2007矩形
  • 一篇文章带你学完链表基础(C语言)
  • 好学易懂 从零开始的插头DP(二)
  • 航空插头在端接的时候我们需要注意哪些问题呢?
  • 这篇关于对警报线程池的警报线程_您可能对警报对话框不了解的地方的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



    http://www.chinasem.cn/article/360175

    相关文章

    Linux线程之线程的创建、属性、回收、退出、取消方式

    《Linux线程之线程的创建、属性、回收、退出、取消方式》文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthr... 目录1. 线程号2. 线程的创建3. 线程属性4. 线程的回收5. 线程的退出6. 线程的取消7.

    Linux下进程的CPU配置与线程绑定过程

    《Linux下进程的CPU配置与线程绑定过程》本文介绍Linux系统中基于进程和线程的CPU配置方法,通过taskset命令和pthread库调整亲和力,将进程/线程绑定到特定CPU核心以优化资源分配... 目录1 基于进程的CPU配置1.1 对CPU亲和力的配置1.2 绑定进程到指定CPU核上运行2 基于

    Javaee多线程之进程和线程之间的区别和联系(最新整理)

    《Javaee多线程之进程和线程之间的区别和联系(最新整理)》进程是资源分配单位,线程是调度执行单位,共享资源更高效,创建线程五种方式:继承Thread、Runnable接口、匿名类、lambda,r... 目录进程和线程进程线程进程和线程的区别创建线程的五种写法继承Thread,重写run实现Runnab

    SpringBoot线程池配置使用示例详解

    《SpringBoot线程池配置使用示例详解》SpringBoot集成@Async注解,支持线程池参数配置(核心数、队列容量、拒绝策略等)及生命周期管理,结合监控与任务装饰器,提升异步处理效率与系统... 目录一、核心特性二、添加依赖三、参数详解四、配置线程池五、应用实践代码说明拒绝策略(Rejected

    Java 线程安全与 volatile与单例模式问题及解决方案

    《Java线程安全与volatile与单例模式问题及解决方案》文章主要讲解线程安全问题的五个成因(调度随机、变量修改、非原子操作、内存可见性、指令重排序)及解决方案,强调使用volatile关键字... 目录什么是线程安全线程安全问题的产生与解决方案线程的调度是随机的多个线程对同一个变量进行修改线程的修改操

    Java中实现线程的创建和启动的方法

    《Java中实现线程的创建和启动的方法》在Java中,实现线程的创建和启动是两个不同但紧密相关的概念,理解为什么要启动线程(调用start()方法)而非直接调用run()方法,是掌握多线程编程的关键,... 目录1. 线程的生命周期2. start() vs run() 的本质区别3. 为什么必须通过 st

    Linux实现线程同步的多种方式汇总

    《Linux实现线程同步的多种方式汇总》本文详细介绍了Linux下线程同步的多种方法,包括互斥锁、自旋锁、信号量以及它们的使用示例,通过这些同步机制,可以解决线程安全问题,防止资源竞争导致的错误,示例... 目录什么是线程同步?一、互斥锁(单人洗手间规则)适用场景:特点:二、条件变量(咖啡厅取餐系统)工作流

    Java中常见队列举例详解(非线程安全)

    《Java中常见队列举例详解(非线程安全)》队列用于模拟队列这种数据结构,队列通常是指先进先出的容器,:本文主要介绍Java中常见队列(非线程安全)的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录一.队列定义 二.常见接口 三.常见实现类3.1 ArrayDeque3.1.1 实现原理3.1.2

    SpringBoot3中使用虚拟线程的完整步骤

    《SpringBoot3中使用虚拟线程的完整步骤》在SpringBoot3中使用Java21+的虚拟线程(VirtualThreads)可以显著提升I/O密集型应用的并发能力,这篇文章为大家介绍了详细... 目录1. 环境准备2. 配置虚拟线程方式一:全局启用虚拟线程(Tomcat/Jetty)方式二:异步

    如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socket read timed out的问题

    《如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socketreadtimedout的问题》:本文主要介绍解决Druid线程... 目录异常信息触发场景找到版本发布更新的说明从版本更新信息可以看到该默认逻辑已经去除总结异常信息触发场景复