不多说直接贴代码
public class DialogMemberUtil {
private OnClick onClick;
public Dialog dialog;
public Dialog dialogLoading;
public void setOnClick(OnClick onClick){
this.onClick = onClick;
}
public interface OnClick{
void leftClick();
void rightClick();
}
public void infoDialog(Context context,String title, CharSequence info, String leftIsShow, String rightIsShow) {
dialog = new Dialog(context, R.style.CustomDialog);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dv = inflater.inflate(R.layout.layout_infomind, null);
TextView text_title = (TextView) dv.findViewById(R.id.text_title);
TextView text_info = (TextView) dv.findViewById(R.id.text_info);
TextView text_sure = (TextView) dv.findViewById(R.id.text_sure);
TextView text_dismiss = (TextView) dv.findViewById(R.id.text_dismiss);
text_title.setText(title);
text_info.setText(info);
text_dismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClick.rightClick();
}
});
text_sure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClick.leftClick();
}
});
text_dismiss.setText(leftIsShow);
text_sure.setText(rightIsShow);
dialog.setContentView(dv);
dialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
dialog.show();
}
/**
* 显示loading弹窗
*
* @param context
* @param msg
* @return
*/
public void showLoadingDialog(Context context, String msg) {
dialogLoading = new Dialog(context, R.style.CustomDialog);
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.dialog_loading, null);
LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);
// main.xml中的ImageView
ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);
// 加载动画
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(context, R.anim.rotating);
// 使用ImageView显示动画
spaceshipImage.startAnimation(hyperspaceJumpAnimation);
tipTextView.setText(msg);// 设置加载信息
dialogLoading.setContentView(v);
dialogLoading.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
dialogLoading.show();
}
public void dismiss(){
if(dialogLoading != null){
dialogLoading.dismiss();
}
}
}
XML 布局
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="@dimen/margin_50"
android:layout_marginRight="@dimen/margin_50"
android:background="@drawable/white_corner_bg"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="@dimen/ui_30">
<TextView
android:id="@+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/ui_30"
android:gravity="center_vertical"
android:paddingLeft="@dimen/navigation_bar_edit_margin"
android:paddingRight="@dimen/navigation_bar_edit_margin"
android:text="退出登录"
android:textColor="@color/gray3"
android:textSize="@dimen/font_30" />
<TextView
android:id="@+id/text_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/ui_30"
android:gravity="center_vertical"
android:paddingLeft="@dimen/navigation_bar_edit_margin"
android:paddingRight="@dimen/navigation_bar_edit_margin"
android:text="您确定要退出登录吗?"
android:textColor="@color/color_9B9B9B"
android:textSize="@dimen/font_30" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="@color/gray_bg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text_sure"
android:layout_width="0dp"
android:layout_height="@dimen/ui_88"
android:layout_weight="0.5"
android:gravity="center"
android:text="确定"
android:textColor="@color/color_f16158"
android:textSize="@dimen/font_30" />
<View
android:layout_width="2px"
android:layout_height="match_parent"
android:background="@color/gray_bg" />
<TextView
android:id="@+id/text_dismiss"
android:layout_width="0dp"
android:layout_height="@dimen/ui_88"
android:layout_weight="0.5"
android:gravity="center"
android:text="取消"
android:textColor="@color/color_f16158"
android:textSize="@dimen/font_30" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
上面主要是一个简单自定义对话框,即插即用,色调自己改动.