您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 自定义Dialog弹窗
  所属分类: Android
  开发工具:
  文件大小: 16mb
  下载次数: 0
  上传时间: 2017-10-12
  提 供 者: zxz837******
 详细说明: 从底部弹出的dialog。位置你可以在base里自己改。使用方法都有。public class BaseDialog extends Dialog { private View mContentView; public Context mContext; public LayoutInflater mInflater; public BaseDialog(Context context) { this(context, R.style.BaseDialogStyle); mContext = context; } public BaseDialog(Context context, int themeResId) { super(context, themeResId); mContext = context; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.dialog_base); Window dialogWindow = getWindow(); WindowManager.LayoutParams lp1 = dialogWindow.getAttributes(); WindowManager wm = (WindowManager) getContext() .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); int width = outMetrics.widthPixels; lp1.width = width; dialogWindow.setGravity(Gravity.BOTTOM); dialogWindow.setAttributes(lp1); mInflater = LayoutInflater.from(mContext); } public void setContentView(int layoutResID) { mContentView = View.inflate(mContext, layoutResID, null); LinearLayout view = (LinearLayout) findViewById(R.id.base_container); view.addView(mContentView); } public View getContextView() { return mContentView; } } public class CustomDialog extends BaseDialog implements View.OnClickListener { /** * 标题 */ private TextView mTitleTv; /** * 确定按钮 */ private Button mPositiveBt; /** * 取消按钮 */ private Button mNegativeBt; /** * 确定取消中间分割线 */ private View mDiverView; /** * 内容容器 */ private LinearLayout mContentLin; private View.OnClickListener mPositiveClickListener; private View.OnClickListener mNegativeClickListener; private List mContents; private String mContent; private String mTilte; private String mPositiveText; private String mNegativeText; private CustomDialog(Context context) { super(context); } private CustomDialog(Context context, int themeResId) { super(context, themeResId); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_one_button); mTitleTv = (TextView) findViewById(R.id.title); mContentLin = (LinearLayout) findViewById(R.id.container); mPositiveBt = (Button) findViewById(R.id.positiveButton); mNegativeBt = (Button) findViewById(R.id.negativeButton); mDiverView = findViewById(R.id.diver); mPositiveBt.setOnClickListener(this); mNegativeBt.setOnClickListener(this); setContent(mContent); setContents(); setTitle(); setButtonClickListener(); setNegativeBtText(); setPositiveBtText(); } private void setContents() { if (mContents != null && mContents.size() != 0) { if (mContents.size() == 1) { setContent(mContents.get(0)); } else { for (int i = 0; i < mContents.size(); i++) { View view = mInflater.inflate(R.layout.diaolog_content_item_left, null); TextView tv = (TextView) view.findViewById(R.id.tv); tv.setText(mContents.get(i)); mContentLin.addView(view); } } } } private void setContent(String content) { if (!TextUtils.isEmpty(content)) { View view = mInflater.inflate(R.layout.diaolog_content_item_center, null); TextView tv = (TextView) view.findViewById(R.id.tv); tv.setText(content); mContentLin.addView(view); } } /** * 设置标题 */ private void setTitle() { if (!TextUtils.isEmpty(mTilte)) { mTitleTv.setVisibility(View.VISIBLE); mTitleTv.setText(mTilte); } } /** * 设置右侧按钮的显示文字,默认为确定 */ private void setPositiveBtText() { if (!TextUtils.isEmpty(mPositiveText)) { mPositiveBt.setText(mPositiveText); } } /** * 设置左侧按钮的显示文字,默认为取消 */ private void setNegativeBtText() { if (!TextUtils.isEmpty(mNegativeText)) { mNegativeBt.setText(mNegativeText); } } /** * 设置监听 可不设置 */ private void setButtonClickListener() { if (mPositiveClickListener != null) { mPositiveBt.setVisibility(View.VISIBLE); } if (mNegativeClickListener != null) { mNegativeBt.setVisibility(View.VISIBLE); } if (mNegativeClickListener != null && mPositiveClickListener != null) { mDiverView.setVisibility(View.VISIBLE); } } public static class Builder { private CustomDialog dialog; public Builder(Context context) { dialog = new CustomDialog(context); } public Builder(Context context, int themeResId) { dialog = new CustomDialog(context, themeResId); } /** * 通过Builder类创建dialog */ public CustomDialog create() { return dialog; } /** * 多条提示 */ public Builder setContent(List contents) { dialog.mContents = contents; return this; } /** * 单条提示 */ public Builder setContent(String content) { dialog.mContent = content; return this; } /** * 设置标题 */ public Builder setTitle(String tilte) { dialog.mTilte = tilte; return this; } /** * 设置右侧按钮的显示文字,默认为确定 * * @param positiveText 按钮上的显示内容 */ public Builder setPositiveBtText(String positiveText) { dialog.mPositiveText = positiveText; return this; } /** * 设置左侧按钮的显示文字,默认为取消 * * @param negativeText 按钮上的显示内容 */ public Builder setNegativeBtText(String negativeText) { dialog.mNegativeText = negativeText; return this; } ; /** * 设置监听 可不设置 * * @param positiveClickListener 确定按钮 * @param negativeClickListener 确定取消按钮 */ public Builder setButtonClickListener(View.OnClickListener positiveClickListener, View.OnClickListener negativeClickListener) { dialog.mPositiveClickListener = positiveClickListener; dialog.mNegativeClickListener = negativeClickListener; return this; } } @Override public void onClick(View v) { switch (v.getId()) { case R.id.positiveButton: if (mPositiveClickListener != null) { mPositiveClickListener.onClick(v); dismiss(); } break; case R.id.negativeButton: if (mNegativeClickListener != null) { mNegativeClickListener.onClick(v); dismiss(); } break; } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 自定义Dialog
 输入关键字,在本站1000多万海量源码库中尽情搜索: