温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

HTML怎么自定义dialog背景

发布时间:2020-09-22 11:35:26 来源:亿速云 阅读:171 作者:小新 栏目:web开发

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背景的简单过程了,要想了解的更多,请上亿速云了解更多知识。

现在我们说说如何自定义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>

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

感谢各位的阅读!看完上述内容,你们对HTML怎么自定义dialog背景大概了解了吗?希望文章内容对大家有所帮助。如果想了解更多相关文章内容,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI