Android使用指定的View开发弹窗功能

Android开发中进程会使用到我们的AlertDialog,但是比较可惜的是我们的Android原生的AlertDialog的效果又比较的简陋,这个时候我们就需要自定义的View去显示了。

Overview

Android 中的AlertDialog 的效果十分的的炫酷。

他的效果是类似弹窗的效果。

那么我们就可以拿他来做很多事情,比如点击添加时,弹出我们的AlertDialog 的效果就十分的棒。那就让我们看一下如何使用它。

首先 我们看一下 我们的 自定义的view 的布局。

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:app="http://schemas.android.com/apk/res-auto"
  3. android:layout_width="400dp"
  4. android:layout_height="470dp"
  5. android:orientation="vertical">
  6. <LinearLayout
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. android:layout_marginLeft="10dp"
  10. android:layout_marginTop="20dp"
  11. android:layout_marginRight="10dp"
  12. android:layout_marginBottom="20dp"
  13. android:orientation="vertical">
  14. <LinearLayout
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:orientation="horizontal">
  18. <EditText
  19. android:id="@+id/editTodoItems"
  20. android:layout_width="0dp"
  21. android:layout_height="wrap_content"
  22. android:layout_weight="8"
  23. android:hint="今天打算做什么?"
  24. android:textColor="#000000"
  25. android:textSize="14sp" />
  26. <TextView
  27. android:id="@+id/TodotxtAddItems"
  28. android:layout_width="0dp"
  29. android:layout_height="wrap_content"
  30. android:layout_weight="2"
  31. android:gravity="center"
  32. android:text="添加"
  33. android:textColor="@color/MainColor"
  34. android:textSize="18sp"
  35. android:textStyle="bold" />
  36. </LinearLayout>
  37. <LinearLayout
  38. android:layout_width="match_parent"
  39. android:layout_height="wrap_content"
  40. android:orientation="horizontal">
  41. <androidx.cardview.widget.CardView
  42. android:layout_width="wrap_content"
  43. android:layout_height="35dp"
  44. android:backgroundTint="@color/dark"
  45. app:cardCornerRadius="20dp">
  46. <LinearLayout
  47. android:id="@+id/today"
  48. android:layout_width="match_parent"
  49. android:layout_height="match_parent"
  50. android:orientation="vertical">
  51. <TextView
  52. android:layout_width="match_parent"
  53. android:layout_height="match_parent"
  54. android:layout_marginLeft="15dp"
  55. android:layout_marginTop="10dp"
  56. android:layout_marginRight="15dp"
  57. android:layout_marginBottom="10dp"
  58. android:text="今天"
  59. android:textColor="#fff"
  60. android:textSize="12sp" />
  61. </LinearLayout>
  62. </androidx.cardview.widget.CardView>
  63. <androidx.cardview.widget.CardView
  64. android:layout_width="wrap_content"
  65. android:layout_height="35dp"
  66. android:layout_marginLeft="10dp"
  67. android:backgroundTint="@color/dark"
  68. app:cardCornerRadius="20dp">
  69. <LinearLayout
  70. android:id="@+id/tomorrow"
  71. android:layout_width="match_parent"
  72. android:layout_height="match_parent"
  73. android:orientation="vertical">
  74. <TextView
  75. android:layout_width="match_parent"
  76. android:layout_height="wrap_content"
  77. android:layout_marginLeft="15dp"
  78. android:layout_marginTop="10dp"
  79. android:layout_marginRight="15dp"
  80. android:layout_marginBottom="10dp"
  81. android:text="明天"
  82. android:textColor="#fff"
  83. android:textSize="12sp" />
  84. </LinearLayout>
  85. </androidx.cardview.widget.CardView>
  86. <androidx.cardview.widget.CardView
  87. android:layout_width="wrap_content"
  88. android:layout_height="35dp"
  89. android:layout_marginLeft="10dp"
  90. android:backgroundTint="@color/dark"
  91. app:cardCornerRadius="20dp">
  92. <LinearLayout
  93. android:id="@+id/selectDay"
  94. android:layout_width="match_parent"
  95. android:layout_height="match_parent"
  96. android:orientation="vertical">
  97. <TextView
  98. android:id="@+id/Day3"
  99. android:layout_width="match_parent"
  100. android:layout_height="match_parent"
  101. android:layout_marginLeft="15dp"
  102. android:layout_marginTop="10dp"
  103. android:layout_marginRight="15dp"
  104. android:layout_marginBottom="10dp"
  105. android:gravity="center"
  106. android:text="选择日期"
  107. android:textColor="#fff"
  108. android:textSize="12sp" />
  109. </LinearLayout>
  110. </androidx.cardview.widget.CardView>
  111. <androidx.cardview.widget.CardView
  112. android:layout_width="wrap_content"
  113. android:layout_height="35dp"
  114. android:layout_marginLeft="10dp"
  115. android:backgroundTint="@color/dark"
  116. app:cardCornerRadius="20dp">
  117. <LinearLayout
  118. android:id="@+id/intoBox"
  119. android:layout_width="match_parent"
  120. android:layout_height="match_parent"
  121. android:orientation="vertical">
  122. <TextView
  123. android:layout_width="match_parent"
  124. android:layout_height="match_parent"
  125. android:layout_marginLeft="15dp"
  126. android:layout_marginTop="10dp"
  127. android:layout_marginRight="15dp"
  128. android:layout_marginBottom="10dp"
  129. android:text="
  130. Android 中的AlertDialog使用自定义布局的更多相关文章

      1. Android中ListView同过自定义布局并使用SimpleAdapter的方式实现数据的绑定
      1. 1.listview的数据填充可以通过ArrayAdapter,SimpleAdapter,也可以是一个xml文件,但是ArrayAdapter与SimpleAdapter的区别是: 2 ArrayA ...

      1. Android中使用ListView绘制自定义表格(2)
      1. 上回再写了<Android中使用ListView绘制自定义表格>后,很多人留言代码不全和没有数据样例.但因为项目原因,没法把源码全部贴上来.近两天,抽空简化了一下,做了一个例子. 效果图如 ...

      1. Android中使用AlertDialog实现几种不同的对话框
      1. 场景 app中常见的对话框. 简单的带确定取消按钮的对话框 带列表的对话框 带单项选择的对话框 带多项选择的对话框 注: 博客: https://blog.csdn.net/badao_liumang ...

      1. Android中常用的5大布局详述
      1. Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面. 所有的布局方式都可以归类为ViewGroup的 ...

      1. Android中SimpleAdapter的使用—自定义列表
      1. 本人初学Android,今天研究到Adapter这块感觉挺有意思的,写了个自定义列表进行测试 首先我们新建一个layout列表布局文件,具体布局可以自己设定. 下面贴上我的自定义布局文件代码 < ...

      1. Android中intent如何传递自定义数据类型
      1. 转载自:http://www.cnblogs.com/GoAhead/archive/2012/07/16/2593868.html 大家好,好久不见,今天要给大家讲一下Android中Intent中 ...

      1. Android中为TextView增加自定义的HTML标签
      1. Android中的TextView,本身就支持部分的Html格式标签.这其中包括常用的字体大小颜色设置,文本链接等.使用起来也比较方便,只需要使用Html类转换一下即可.比如: textView.se ...

      1. Android中的通知—Notification 自定义通知
      1. Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...

      1. Android中的AlertDialog使用示例五(自定义对话框)
      1. 在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

    1. 随机推荐

        1. Missing associated label more...
        1. 1.加上placeholder,可以为空 2.放在label标签中

        1. Geoserver发布服务
        1. Geoserver发布服务的数据源很多样化 在数据存储中选择要发布的数据来源,这里以POSTGIS为例 1. 2.如果成功,就会读取出库里面的表,你可以在这里添加图层,发布服务 3.点击发布,进行服务 ...

        1. Chrome 开发者工具实用操作
        1. Chrome 开发者工具实用操作 https://umaar.com/dev-tips/

        1. java 监听文件或文件夹变化
        1. 今天遇到一个新需求,当从服务器下载文件后用指定的本地程序打开,不知道何时文件下载完成,只能考虑监听文件夹,当有新文件创建的时候打开指定程序. 在此给出一个完整的下载和打开过程: 1.下载文件 jsp页 ...

        1. GNN 相关资料记录;GCN 与 graph embedding 相关调研
        1. 最近做了一些和gnn相关的工作,经常听到GCN 和 embedding 相关技术,感觉很是困惑,所以写下此博客,对相关知识进行索引和记录: 参考链接: https://www.toutiao.com/ ...

        1. JVM基础回顾记录(二):垃圾收集
        1. 垃圾收集流程&HotSpot对该流程的实现方式 上一篇介绍了jvm的内存模型,本篇将介绍虚拟机中最为复杂的一部分:垃圾收集,本篇会从垃圾回收前的准备工作到后面的收集阶段的方式以及HotSpot ...

        1. day100_12_4DataFrame和matplotlib模块
        1. 一.Dataframe的分组. 再网页表格数据 的分析中,可以使用以下语句进行爬取表格. res = pd.read_html('https://baike.baidu.com/item/NBA%E6 ...

        1. Springcloud 微服务 高并发(实战1):第1版秒杀
        1. 疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列之15 [博客园总入口 ] 前言 前言 疯狂创客圈(笔者尼恩创建的高并发研习社群)Springcloud 高并发系列文章,将为大家介绍三个版 ...

        1. 【RTOS】基于V7开发板的RTX5和FreeRTOS带CMSIS-RTOS V2封装层的模板例程下载,AC6和AC5两个版本
        1. 说明: 1.使用MDK的RTE环境开发RTX5和FreeRTOS,简单易移植,统一采用CMSIS-RTOS V2封装层. 2.DTCM是H7里面性能最高的RAM,主频400MHz,跟内核速度一样,所以 ...

        1. 关于dom4j解析XML的问题分享
        1. 最近在在做个程序需要将C#小工具转成java,因为需要涉及到操作xml文件所以需要引用dom4j: 使用dom4j解析XML时,要快速获取某个节点的数据,使用XPath是个不错的方法,dom4j的快速 ...