真谛的精力和的精力是社会的支柱。如果大师时经常使用过微信或者用过iphone,就会发明有种从底部弹出的半透明菜单,这种菜单风格精美而且用户体验杰出,先看一下结果。 java
真正的友情历来不会安静冷静僻静无波。 微信
MMAlert来自微信开放平台的sdk示例,其示例的代码有点乱,我作了删减和收拾,只保存了MMAlert这个类的一项目组功能,即只保存了实现上述结果的那个函数,由于其余函数斗劲简单,就是通俗的AlertDialog,我感受大师都懂,因此直接删掉了。 app
代码介绍 iphone
1 . 下面这段代码其实蛮好懂得的,本质就是new一个对话框,而后将其放置在底部,为其设置theme和style,theme和style写的蛮好懂得的, 具体大师能够看源码。数据浮现用的是Listview,为此咱们需要new一个BaseAdapter对象来经管数据,BaseAdapter没什么特别 之处,很好懂得,具体请看代码。 ide
/** * @param context * Context. * @param title * The title of this AlertDialog can be null . * @param items * button name list. * @param alertDo * methods call Id:Button + cancel_Button. * @param exit * Name can be null.It will be Red Color * @return A AlertDialog */ public static Dialog showAlert(final Context context, final String title, final String[] items, String exit, final OnAlertSelectId alertDo, OnCancelListener cancelListener) { String cancel = context.getString(R.string.app_cancel); final Dialog dlg = new Dialog(context, R.style.MMTheme_DataSheet); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.alert_dialog_menu_layout, null); final int cFullFillWidth = 10000; layout.setMinimumWidth(cFullFillWidth); final ListView list = (ListView) layout.findViewById(R.id.content_list); AlertAdapter adapter = new AlertAdapter(context, title, items, exit, cancel); list.setAdapter(adapter); list.setDividerHeight(0); list.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (!(title == null || title.equals("")) && position - 1 >= 0) { alertDo.onClick(position - 1); dlg.dismiss(); list.requestFocus(); } else { alertDo.onClick(position); dlg.dismiss(); list.requestFocus(); } } }); // set a large value put it in bottom Window w = dlg.getWindow(); WindowManager.LayoutParams lp = w.getAttributes(); lp.x = 0; final int cMakeBottom = -1000; lp.y = cMakeBottom; lp.gravity = Gravity.BOTTOM; dlg.onWindowAttributesChanged(lp); dlg.setCanceledOnTouchOutside(true); if (cancelListener != null) dlg.setOnCancelListener(cancelListener); dlg.setContentView(layout); dlg.show(); return dlg; }2. 如何应用MMAlert?很简单!
findViewById(R.id.send_img).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MMAlert.showAlert(SendToWXActivity.this, getString(R.string.send_img), SendToWXActivity.this.getResources().getStringArray(R.array.send_img_item), null, new MMAlert.OnAlertSelectId(){ @Override public void onClick(int whichButton) { switch(whichButton){ case MMAlertSelect1: { break; } case MMAlertSelect2: { break; } case MMAlertSelect3: { break; } default: break; } } }); } });
代码 函数
http://download.csdn.net/detail/singwhatiwanna/5338394 this
或者http://www.kuaipan.cn/file/id_105515054266321788.htm谚语 .net