Android的PopupWindow是个很有用的widget,利用它可以实现悬浮窗体的效果,比如实现一个悬浮的菜单,最常见的应用就是在视频播放界面里,做一个工具栏,用来控制播放进度。本文利用PopupWindow来实现一个通用的Dailog,类似Android系统的AlertDailog,从中学习和掌握有关PopupWindow和Dailog的使用和实现细节。
成都创新互联公司主营疏勒网站建设的网络公司,主营网站建设方案,app软件开发,疏勒h5微信小程序开发搭建,疏勒网站营销推广欢迎疏勒等地区企业咨询界面效果如图所示,点击 Click 按钮后,弹出对话框提示。
(1). CustomDailog的布局
首先定义 CustDailog的布局文件,由系统的AlertDailog可以知道,一个对话框包含了三个要素,一个是Title,即标题,一个是Message,即主体内容,还有一个是Button,即确定和取消的按钮,用来与用户交互。因此,布局设计如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/shape_bg" android:layout_margin="10dp"> <TextView android:id="@+id/CustomDlgTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20sp" android:layout_margin="10dp" android:gravity="center"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray"/> <LinearLayout android:id="@+id/CustomDlgContentView" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="5dp" /> <TextView android:id="@+id/CustomDlgContentText" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" android:layout_margin="5dp" android:paddingLeft="5sp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_margin="5dp" > <Button android:id="@+id/CustomDlgButtonOK" android:layout_width="0dp" android:layout_weight="0.5" android:layout_height="wrap_content" android:visibility="gone"/> <Button android:id="@+id/CustomDlgButtonCancel" android:layout_width="0dp" android:layout_weight="0.5" android:layout_height="wrap_content" android:visibility="gone"/> </LinearLayout> </LinearLayout>
本文名称:Android用PopupWindow实现自定义Dailog-创新互联
当前URL:https://www.cdcxhl.com/article18/ppjdp.html
成都网站建设公司_创新互联,为您提供建站公司、外贸网站建设、定制开发、网站排名、全网营销推广、品牌网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联