[Anko]使用anko alert示例

本文介绍了一种使用自定义布局创建对话框的方法,包括设置标题、输入任务项及添加按钮的功能实现。此外还展示了如何通过不可取消的警告对话框来处理用户被迫离线的情况。
alert { 
      customView { 
          verticalLayout { 
         //对话框标题 
          toolbar {
         id = R.id.dialog_toolbar                                lparams(width = matchParent, height = wrapContent) 
         backgroundColor = ContextCompat.getColor(ctx, R.color.colorAccent) 
        title = "What's your next milestone?"                                setTitleTextColor(ContextCompat.getColor(ctx, android.R.color.white)) 
         } 
       val task = editText { 
              hint = "To do task "
             padding = dip(20) 
       } 
        positiveButton("Add") { 
              if(task.text.toString().isEmpty()) { 
                toast("Oops!! Your task says nothing!") 
               }                                else { 
             adapter.add(task.text.toString())                                    showHideHintListView(todoList!!) 
               } 
            }
         } 
       }
    }.show()

 

context?.alert("You are forced to be offline. Please try to login again.") {
                title = "Warning"
                isCancelable = false
                positiveButton("OK" ){
                    ActivityCollector.finishAll()
                    context.startActivity<LoginActivity>()
                }
            }?.show()

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值