自定义AlertDialog的实现步骤

package com.micen.suppliers.business.home;


import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;


import com.focustech.common.db.SharedPreferenceManager;
import com.micen.suppliers.R;


/**********************************************************
 * @文件名称:UpdateMsgDialog.java
 * @文件作者:chengsheng
 * @创建时间:2016年4月28日 下午3:01:38
 * @文件描述:更新后首次进入展示更新内容
 * @修改历史:2016年4月28日创建初始版本
 **********************************************************/
public class UpdateMsgDialog extends AlertDialog
{
private ImageView toMsg;


private ImageView iKnow;
private ImageView updateMsg;
private HomeActivity activity;


public UpdateMsgDialog(Context context, int theme)
{


super(context, theme);
activity = (HomeActivity) context;
}


public UpdateMsgDialog(Context context)
{
super(context);
}


@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.update_msg_dialog);
toMsg = (ImageView) findViewById(R.id.iv_to_msg);
updateMsg = (ImageView) findViewById(R.id.iv_update_msg);
iKnow = (ImageView) findViewById(R.id.iv_msg_know);
ClickListener listener = new ClickListener();
toMsg.setOnClickListener(listener);
iKnow.setOnClickListener(listener);


}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK){
return true;
}
return super.onKeyDown(keyCode, event);
}
class ClickListener implements View.OnClickListener
{


@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.iv_to_msg:
if (activity instanceof HomeActivity){
activity.broadcastToolBar.callOnClick();
toMsg.setVisibility(View.GONE);
iKnow.setVisibility(View.VISIBLE);
updateMsg.setVisibility(View.VISIBLE);
}
break;
case R.id.iv_msg_know:
SharedPreferenceManager.getInstance().putBoolean("isFirstIn", false);
hide();
break;
default:
break;
}


}


}
}








*********************上述为自定义的dialog,下面为使用这个控件


1.homePresenter.showUpdateMsgDialog();


2.定义的方法
  @Override
    public void showUpdateMsgDialog() {
        UpdateMsgDialog msgDialog = new UpdateMsgDialog(baseView.getTheActivity(), R.style
                .dialog);// 创建Dialog并设置样式主题
        msgDialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域关闭Dialog
        msgDialog.show();
        WindowManager windowManager = baseView.getTheActivity().getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = msgDialog.getWindow().getAttributes();
        lp.width = (int) (display.getWidth()); //设置宽度
        lp.height = (int) (display.getHeight()) - Util.getStatusHeight(baseView.getTheActivity())
        ; //设置高度
        msgDialog.getWindow().setAttributes(lp);
    }

你可能感兴趣的:(自定义AlertDialog的实现步骤)