Android 自定义对话框
不多說直接貼代碼
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>
上面主要是一個簡單自定義對話框,即插即用,色調自己改動.
總結
以上是生活随笔為你收集整理的Android 自定义对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: B.Duck小黄鸭家居产品怎么样?质量如
- 下一篇: 有朋友装修用的是柏尔定制地板吗?价格高不