HTML如何自定义dialog背景?一篇文章教你如何自定义dialog!

互联网 18-8-30
本篇文章主要为大家讲述的是关于HTML中如何自定义dialog标签的背景,还有其它的一些样式设置,代码很多,需要自己的理解,接下来就让我们一起来看关于HTML dialog自定义的文章吧

现在我们先来实现文章的第一个问题,HTML如何自定义dialog标签的背景的:

现在很多App的提示对话框都非常有个性,然而你还用系统的对话框样式,是不是觉得很落后呢,今天我就给大家讲讲怎样自定义自己的Dialog,学会了之后,你就会根据自家app的主题,设计出相应的Dialog的风格。

好了接下来我就以一个简单风格的自定义Dialog来讲讲自定义dialog的一般步骤和原理。

第一步: 给Dialog设置一个风格主题(基本都是用这个主题)无边框全透明背景:

<!--自定义dialog背景全透明无边框theme -->   <style name="MyDialog" parent="android:style/Theme.Dialog">   <!--背景颜色及和透明程度-->   <item name="android:windowBackground">@android:color/transparent</item>   </style>

dialog的自定义背景框如下:

<?xml version="1.0" encoding="utf-8"?>   <shape xmlns:android="http://schemas.android.com/apk/res/android">       <solid android:color="#ffffff" />       <stroke           android:width="0.8dp"           android:color="#ffffff" />       <!-- 圆角 -->       <corners android:radius="6dp" />   </shape>

以上就是在APP中自定义dialog背景的简单过程了,要想了解的更多,请上PHP中文网了解更多知识。

现在我们说说如何自定义dialog:

东西很多,慢慢看

<style name="MyDialog" parent="android:style/Theme.Dialog">           <!--背景颜色及和透明程度-->           <item name="android:windowBackground">@android:color/transparent</item>           <!--是否去除标题 -->           <item name="android:windowNoTitle">true</item>           <!--是否去除边框-->           <item name="android:windowFrame">@null</item>           <!--是否浮现在activity之上-->           <item name="android:windowIsFloating">true</item>           <!--是否模糊-->           <item name="android:backgroundDimEnabled">false</item>   </style>

第二步:给自定的Dialog设置自定义的 xml界面,我这里只是示范,你可以使用单选,多选,3个按钮,4个按钮等等,格式各样的自定义XML,我这里就定义了 标题title,信息message,还有一个确定按钮和取消按钮,如下:

<?xml version="1.0" encoding="utf-8"?>   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"       android:layout_width="match_parent"       android:layout_height="match_parent"       android:background="#11ffffff">         <LinearLayout           android:layout_width="260dp"           android:layout_height="wrap_content"           android:layout_centerInParent="true"           android:background="@drawable/free_dialog_bg"           android:orientation="vertical">             <TextView               android:id="@+id/title"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:layout_gravity="center"               android:layout_margin="15dp"               android:gravity="center"               android:text="消息提示"               android:textColor="#38ADFF"               android:textSize="16sp" />             <TextView               android:id="@+id/message"               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:layout_marginLeft="20dp"               android:layout_marginRight="20dp"               android:text="提示消息" />           <View               android:layout_width="match_parent"               android:layout_height="1px"               android:layout_marginTop="15dp"               android:background="#E4E4E4" />   <LinearLayout               android:layout_width="match_parent"               android:layout_height="40dp"               android:orientation="horizontal">                 <Button                   android:id="@+id/no"                   android:layout_width="0dp"                   android:layout_height="match_parent"                   android:layout_marginLeft="10dp"                   android:layout_weight="1"                   android:background="@null"                   android:gravity="center"                   android:singleLine="true"                   android:text="No"                   android:textColor="#7D7D7D"                   android:textSize="16sp" />                 <View                   android:layout_width="1px"                   android:layout_height="match_parent"                   android:background="#E4E4E4" />                 <Button                   android:id="@+id/yes"                   android:layout_width="0dp"                   android:layout_height="match_parent"                   android:layout_marginRight="10dp"                   android:layout_weight="1"                   android:background="@null"                   android:gravity="center"                   android:singleLine="true"                   android:text="Yes"                   android:textColor="#38ADFF"                   android:textSize="16sp" />           </LinearLayout>       </LinearLayout>     </RelativeLayout>

dialog的自定义背景框如下:

<?xml version="1.0" encoding="utf-8"?>   <shape xmlns:android="http://schemas.android.com/apk/res/android">       <solid android:color="#ffffff" />       <stroke           android:width="0.8dp"           android:color="#ffffff" />       <!-- 圆角 -->       <corners android:radius="6dp" />   </shape>

这就完成了虽然很长,但是学习是个很慢的过程。一点一点的来吧

好了,本篇文章到这也就结束了,欢迎大家的观看,有什么疑问可以在下方提问。

【小编推荐】

html5 footer标签怎么用?footer标签的用法实例

html frame标签怎么使用?frame标签的用法介绍(附实例)

以上就是HTML如何自定义dialog背景?一篇文章教你如何自定义dialog!的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: html
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:html frame标签怎么使用?frame标签的用法介绍(附实例)

相关资讯