自定义dialog思路

构建自己定义的dialog思路:首先extends builder;
将alertdialog加入其中,然后Inflater一个layout,
成为一个view 将此view set成alertdialog 的view。
然后 implements android.view.View.OnClickListener
这样在封装的setonclicklistener接口时,即可调用
setonclicklistener(this);点击时回调OnClick();在此回调中
mAlertDialog.dismiss();
关键代码:
  LayoutInflater layoutInflater = LayoutInflater.from(context);
  mBaseView = layoutInflater.inflate(R.layout.satellite_select_dialog,
    null);
  public AlertDialog show() {
  mAlertDialog = super.show();
  mAlertDialog.setContentView(mBaseView);

  WindowManager.LayoutParams lp = mAlertDialog.getWindow()
    .getAttributes();
  lp.width = (int) (600);
  lp.height = (int) (530);
  lp.alpha = 0.95f;
  mAlertDialog.getWindow().setAttributes(lp);
  return mAlertDialog;
 }
 
第二种dialog自定义方法:关键:window.setContentView(view); 在dialog的window上设置view   
final AlertDialog dlg = new AlertDialog.Builder(mContext).create();
  dlg.show();
  
  Window window = dlg.getWindow();
  LayoutParams params = window.getAttributes();
  params.width = 600;
  window.setAttributes(params);
  
  View view = LayoutInflater.from(mContext).inflate(R.layout.avset_dialog, null);
  list = (ListView) view.findViewById(R.id.list);
  list.setOnKeyListener(list_OnKeyListener);
  list.setOnItemSelectedListener(list_OnItemSelectedListener);
  
  adapter = new MyAdapter(mContext);
  list.setAdapter(adapter);
  window.setContentView(view);
 listview 选中背景更换 
  android:listSelector="@layout/avset_item_style"
  class MyAdapter extends base
手势识别:
mGesture = new GestureDetector(this, new GestureListener());  

popmenu()
public class PopupMenuGridItem
{
 public int m_imageId;
 public String m_title;
 public OnItemClickListener m_onItemClickListener;
}

 public void setMenuContent(ArrayList<PopupMenuGridItem> contentList)
 {
  m_contentList = contentList;
  if(m_contentList == null)
  {
   m_contentList = new ArrayList<PopupMenuGridItem>();
  }
 } 
 public void showAsDropDown(View view, int xOffset, int yOffset)
    {
     createMenuPopupwindow();
     m_popupWindow.showAsDropDown(view, xOffset, yOffset);
    }
    createMenuPopupwindow(){
     
     }

你可能感兴趣的:(自定义dialog思路)