首页 > 学院 > 开发设计 > 正文

特殊布局的对话框

2019-11-09 18:41:49
字体:
来源:转载
供稿:网友

实现下面这种对话框效果

这里写图片描述

1、写好布局文件success_dialog_style.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_all" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent"> <RelativeLayout android:id="@+id/relativeLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginTop="20dp" android:background="@drawable/white_shadow"> <TextView android:id="@+id/tv_is_success" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="15dp" android:layout_marginTop="40dp" android:gravity="center_horizontal" android:text="恭喜, 抢单成功!" android:textColor="#333333" android:textSize="25sp" /> <TextView android:id="@+id/tv_tips" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tv_is_success" android:layout_centerHorizontal="true" android:layout_marginBottom="20dp" android:layout_marginLeft="15sp" android:layout_marginRight="15dp" android:gravity="center_horizontal" android:maxEms="14" android:text="请登录网页端,在 【我的任务—进行中】页面查看抢到的任务。" android:textColor="#666666" android:textSize="17sp" /> </RelativeLayout> <ImageView android:id="@+id/iv_is_success" android:layout_width="60dp" android:layout_height="60dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_gravity="center_horizontal" android:src="@drawable/success" /></RelativeLayout>

2、自定义对话框CompeteOrderDialog.java

import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.text.Spanned;import android.view.View;import android.widget.ImageView;import android.widget.RelativeLayout;import android.widget.TextView;import com.shirly.test.R;/** * Created by Mona on 2017/2/5. */public class CompeteOrderDialog extends Dialog { PRivate RelativeLayout btn_close; private TextView tv_is_succedd; private TextView tv_tips; private ImageView iv_is_success; private OnCloseDialogClickListener listener; public void setListener(OnCloseDialogClickListener listener) { this.listener = listener; } private String title; private Spanned tips; private int imgId; public Spanned getTips() { return tips; } public void setTips(Spanned tips) { this.tips = tips; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getImgId() { return imgId; } public void setImgId(int imgId) { this.imgId = imgId; } public CompeteOrderDialog(Context context) { super(context, R.style.CustomerDialog); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.success_dialog_style); //按空白处能取消对话 setCanceledOnTouchOutside(true); //初始化界面控件 initView(); //初始化界面数据 initData(); } private void initData() { tv_is_succedd.setText(title); tv_tips.setText(tips); iv_is_success.setImageResource(imgId); btn_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { listener.onCloseClick(); } }); } private void initView() { btn_close = (RelativeLayout) findViewById(R.id.rl_all); tv_is_succedd = (TextView) findViewById(R.id.tv_is_success); tv_tips = (TextView) findViewById(R.id.tv_tips); iv_is_success = (ImageView) findViewById(R.id.iv_is_success); } public interface OnCloseDialogClickListener { void onCloseClick(); }}

3、在style.xml文件中写一个CustomerDialog样式

<style name="CustomerDialog" 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">true</item> </style>

4、显示对话框

final CompeteOrderDialog dialog = new CompeteOrderDialog(this);dialog.setTitle("恭喜, 抢单成功!");dialog.setImgId(R.drawable.success);dialog.setTips(Html.fromHtml("请登录网页端,在 <font color='#00ADF2'>【我的任务—进行中】</font>页面查看抢到的任务。"));dialog.setListener(new CompeteOrderDialog.OnCloseDialogClickListener() { @Override public void onCloseClick() { dialog.dismiss(); }});dialog.show();
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表