android – 具有自定义形状的DialogFragment

android – 具有自定义形状的DialogFragment,第1张

概述如何使用自定义形状创建对话框片段? 我有一个图标需要放在对话框窗口的顶部(透明). 对话框本身应该是: 对话框布局: <FrameLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" @H_403_4@ 如何使用自定义形状创建对话框片段?

我有一个图标需要放在对话框窗口的顶部(透明).

对话框本身应该是:

对话框布局:

<FrameLayout        androID:orIEntation="vertical"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_margintop="80dp">        <relativeLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:layout_margintop="40dp"            androID:layout_gravity="bottom|center">            <TextVIEw                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:ID="@+ID/server_error_Title"                androID:layout_margintop="80dp"                androID:layout_centerHorizontal="true"                androID:textSize="20sp"                androID:textAllCaps="true"                androID:text="@string/server_error_Title"                androID:textcolor="@color/soft_blue"                androID:FontFamily="sans-serif-medium"/>            <VIEw                androID:layout_wIDth="60dp"                androID:layout_height="2dp"                androID:ID="@+ID/server_error_divIDer"                androID:layout_margintop="21dp"                androID:layout_centerHorizontal="true"                androID:layout_below="@ID/server_error_Title"                androID:background="@color/soft_blue" />            <TextVIEw                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:ID="@+ID/server_error_message"                androID:layout_margintop="19dp"                androID:layout_centerHorizontal="true"                androID:layout_below="@ID/server_error_divIDer"                                androID:text="@string/server_error_message"/>            <VIEw                androID:layout_wIDth="match_parent"                androID:layout_height="1dp"                androID:ID="@+ID/server_error_large_divIDer"                androID:layout_margintop="51dp"                androID:layout_below="@ID/server_error_message"                androID:background="@color/greyish"/>           <linearLayout               androID:layout_wIDth="match_parent"               androID:layout_height="wrap_content"               androID:gravity="center_horizontal"               androID:background="@color/white_grey"               androID:layout_below="@ID/server_error_large_divIDer">               <button                   androID:layout_wIDth="320dp"                   androID:layout_height="46dp"                   androID:ID="@+ID/server_error_close_btn"                   androID:layout_margintop="30dp"                   androID:layout_marginBottom="30dp"                                      androID:text="@string/server_error_close_btn"                   androID:background="@drawable/big_button_shape" />           </linearLayout>        </relativeLayout>        <ImageVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:ID="@+ID/error_dialog_icon"            androID:src="@drawable/ic_error_circle"            androID:layout_gravity="center|top"/>    </FrameLayout>

但我得到的是这个:

我是否需要自定义viewGroup,或者可以更简单地完成它?

@H_403_4@解决方法 使用以下xml示例代码:

<FrameLayout        androID:orIEntation="vertical"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:background="@androID:color/transparent">        <relativeLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:layout_margintop="45dp"            androID:background="@androID:color/white"            androID:layout_gravity="bottom|center">            <TextVIEw                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:ID="@+ID/server_error_Title"                androID:layout_margintop="80dp"                androID:layout_centerHorizontal="true"                androID:textSize="20sp"                androID:textAllCaps="true"                androID:text="@string/server_error_Title"                androID:textcolor="@color/soft_blue"                androID:FontFamily="sans-serif-medium"/>            <VIEw                androID:layout_wIDth="60dp"                androID:layout_height="2dp"                androID:ID="@+ID/server_error_divIDer"                androID:layout_margintop="21dp"                androID:layout_centerHorizontal="true"                androID:layout_below="@ID/server_error_Title"                androID:background="@color/soft_blue" />            <TextVIEw                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:ID="@+ID/server_error_message"                androID:layout_margintop="19dp"                androID:layout_centerHorizontal="true"                androID:layout_below="@ID/server_error_divIDer"                                androID:text="@string/server_error_message"/>            <VIEw                androID:layout_wIDth="match_parent"                androID:layout_height="1dp"                androID:ID="@+ID/server_error_large_divIDer"                androID:layout_margintop="51dp"                androID:layout_below="@ID/server_error_message"                androID:background="@color/greyish"/>           <linearLayout               androID:layout_wIDth="match_parent"               androID:layout_height="wrap_content"               androID:gravity="center_horizontal"               androID:background="@color/white_grey"               androID:layout_below="@ID/server_error_large_divIDer">               <button                   androID:layout_wIDth="320dp"                   androID:layout_height="46dp"                   androID:ID="@+ID/server_error_close_btn"                   androID:layout_margintop="30dp"                   androID:layout_marginBottom="30dp"                                      androID:text="@string/server_error_close_btn"                   androID:background="@drawable/big_button_shape" />           </linearLayout>        </relativeLayout>        <FrameLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_gravity="center_horizontal"        androID:padding="4dp"        androID:background="@drawable/error_circle">        <ImageVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:ID="@+ID/error_dialog_icon"            androID:src="@drawable/ic_error_circle"            androID:layout_gravity="center|top"/>        </FrameLayout>    </FrameLayout>

和error_circle:

<?xml version="1.0" enCoding="utf-8"?><shape xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:innerRadius="0dp"    androID:shape="oval"    androID:useLevel="false" >    <solID androID:color="@androID:color/transparent" />    <stroke        androID:wIDth="45dp"        androID:color="@androID:color/white" /></shape>

编辑:

在DialogFragment的onCreateVIEw()中:

getDialog().requestwindowFeature(Window.FEATURE_NO_Title);getDialog().getwindow().setBackgroundDrawable(new colorDrawable(color.transparent));
@H_403_4@ @H_403_4@ @H_403_4@ @H_403_4@ 总结

以上是内存溢出为你收集整理的android – 具有自定义形状的DialogFragment全部内容,希望文章能够帮你解决android – 具有自定义形状的DialogFragment所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1123229.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存