微信中MMAlert(半透明底部弹出菜单)的使用介绍
来源:互联网 发布:厦门seo技术 编辑:程序博客网 时间:2024/06/06 00:28
如果大家时常用过微信或者用过iphone,就会发现有种从底部弹出的半透明菜单,这种菜单风格优美并且用户体验良好,先看一下效果。
MMAlert来自微信开放平台的sdk示例,其示例的代码有点乱,我做了删减和整理,只保留了MMAlert这个类的一部分功能,即只保留了实现上述效果的那个函数,因为其他函数比较简单,就是普通的AlertDialog,我觉得大家都懂,所以直接删掉了。
代码介绍
1 . 下面这段代码其实蛮好理解的,本质就是new一个对话框,然后将其放置在底部,为其设置theme和style,theme和style写的蛮好理解的,具体大家可以看源码。数据呈现用的是Listview,为此我们需要new一个BaseAdapter对象来管理数据,BaseAdapter没什么特殊之处,很好理解,具体请看代码。
- /**
- * @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
或者http://www.kuaipan.cn/file/id_105515054266321788.htm
0 0
- 微信中MMAlert(半透明底部弹出菜单)的使用介绍
- 微信中MMAlert(半透明底部弹出菜单)的使用介绍
- 使用popupWinow做出底部弹出菜单的效果
- popupwindow 底部弹出+背景半透明
- 仿Iphone从屏幕底部弹出半透明的PopupWindow
- 同时弹出顶部和底部的菜单
- 实现底部弹出菜单
- ExpandableButtonMenu |底部弹出菜单
- android底部弹出菜单
- android 底部弹出菜单
- 仿UC的菜单弹出,布局半透明,控件不受影响。
- popuWindow底部弹出及半透明实现。
- Android实现底部半透明弹出框PopUpWindow
- 底部菜单 BottomNavigationBar 的使用
- android 仿微信底部弹出菜单
- ios 底部弹出框菜单
- ViewDragHelper制作底部弹出菜单
- Dialog 实现底部弹出菜单
- hdu 1671 Phone List (字典树)
- J3续航测试
- (十一)洞悉linux下的Netfilter&iptables:iptables命令行工具源码解析【上】
- hdu_1022(栈问题)&杭电oj_1022
- hdu 1166 敌兵布阵 线段树 单点更新
- 微信中MMAlert(半透明底部弹出菜单)的使用介绍
- php防止乱码
- 登陆 Mac OS SSH 的用户身份验证设置
- java高新技术第一天——反射
- 004_007 在行列表中完成对列的删除或者排序
- [FZU 2055] Noip
- uva101 - The Blocks Problem
- 昨天踩到一坨臭狗屎(与无损压缩有关)
- 从自身出发来选择书与信息