本文简单介绍自定义对话框Dialog的使用,代码和结构都非常简单,目的是能够快速使用自定义对话框,在本文中不具体讲解对话框的高级使用。
实现步骤
首先需要自己在我们的.xml文件中自己构建布局
布局文件做好之后,我们可以在style文件下自己定义布局的样式
前两步都做好之后,我开始在写java文件
具体实现过程
1. xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300dp" android:layout_height="180dp" android:gravity="center" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:background="@android:color/holo_green_light"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical" android:text="IP设置" android:textColor="#fff" android:textSize="24sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#fff" android:gravity="center" android:orientation="horizontal" android:padding="5dp"> <EditText android:id="@+id/et_ip1" android:layout_weight="1" android:inputType="phone" android:maxLength="3" android:textColor="@color/colorPrimary" /> <EditText android:id="@+id/et_ip2" android:layout_weight="1" android:inputType="phone" android:maxLength="3" android:textColor="@color/colorPrimary" /> <EditText android:id="@+id/et_ip3" android:layout_weight="1" android:inputType="phone" android:maxLength="3" android:textColor="@color/colorPrimary" /> <EditText android:id="@+id/et_ip4" android:layout_weight="1" android:inputType="phone" android:maxLength="3" android:textColor="@color/colorPrimary" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="45dp" android:orientation="horizontal"> <Button android:id="@+id/btn_ipok" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/holo_green_light" android:text="确认" android:textColor="#fff" android:textSize="30sp" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#fff" /> <Button android:id="@+id/btn_ipcancle" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/holo_green_light" android:text="取消" android:textColor="#fff" android:textSize="30sp" /> </LinearLayout> </LinearLayout>
新闻名称:Android自定义对话框Dialog-创新互联
当前URL:https://www.cdcxhl.com/article2/docooc.html
成都网站建设公司_创新互联,为您提供品牌网站设计、Google、全网营销推广、关键词优化、域名注册、企业建站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联