(android)微信中MMAlert(半透明底部彈出菜單)的應用介紹

真諦的精力和的精力是社會的支柱。如果大師時經常使用過微信或者用過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

相關文章
相關標籤/搜索