Android 日常封装之暴力CustomViewDialog自定义对话框
2018-02-09 10:53
423 查看
import android.app.Dialog; import android.content.Context; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.StyleRes; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import com.xxx.xxx.R; /** * @author Created by qlang on 2017/5/26. */ public class CustomViewDialog extends Dialog { public CustomViewDialog(@NonNull Context context, @StyleRes int themeResId) { super(context, themeResId); } /** * 实例一个对话框 * * @param context * @param layoutResID 布局资源id * @param cancelable 是否可以按返回键取消 * @param touchOutsideCancelable 是否可以点击外部取消 * @param listener 回调 * @return */ public static CustomViewDialog newInstance(@NonNull Context context, @LayoutRes int layoutResID, boolean cancelable, boolean touchOutsideCancelable, ViewCallBack listener) { View view = LayoutInflater.from(context).inflate(layoutResID, null); return newInstance(context, view, cancelable, touchOutsideCancelable, listener); } /** * 实例一个对话框 * * @param context * @param view view on your show * @param cancelable 是否可以按返回键取消 * @param touchOutsideCancelable 是否可以点击外部取消 * @param listener 回调 * @return */ public static CustomViewDialog newInstance(@NonNull Context context, View view, boolean cancelable, boolean touchOutsideCancelable, final ViewCallBack listener) { CustomViewDialog dialog = new CustomViewDialog(context, R.style.CustomDialogTheme); dialog.setContentView(view); dialog.getWindow().getAttributes().gravity = Gravity.CENTER; dialog.setCanceledOnTouchOutside(touchOutsideCancelable); dialog.setCancelable(cancelable); if (listener != null) { listener.onCallBack(view, dialog); } return dialog; } public interface ViewCallBack { void onCallBack(View contentView, CustomViewDialog dialog); } }
相关文章推荐
- Android 日常封装之暴力CustomActionSheet自定义Fragment从底部弹出界面
- 【Android自定义View实战】之自定义项目通用的加载等待对话框LoadingDialog
- 【Android】高仿QQ对话框之自定义对话框CustomDialog
- Android自定义View(1):对话框-Dialog
- Android对话框(二)进度条对话框ProgressDialog和自定义对话框CustomDialog
- Android AlertDialog 方法setView(view,0,0,0,0)开发自定义对话框
- Android自定义对话框(Custom Dialog)
- Android自定义对话框(Dialog)位置,大小
- android,自定义无标题对话框(继承Dialog类,非AlertDialog)的样式
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- Android快速开发框架Android_BaseLib,集成了常用工具类,自定义View控件,Base基类封装,常用开源框架
- android 自定义对话框 Dialog
- Android中的普通对话框、单选对话框、多选对话框、带Icon的对话框、以及自定义Adapter和自定义View对话框详解
- Android自定义对话框(Dialog)位置,大小
- 完全自定义Android对话框AlertDialog的实现(系统源码)
- Android自定义样式(风格)的dialog对话框(点击其中的按钮跳转到下一个页面)
- Android-自定义View之重写控件(自定义Dialog)
- Androidの自定义对话框AlertDialog(二)
- android 自定义View对Title的封装