在actionbar的PopupWindow

public void initPopData() {
		itemList.add(new PopMenuItem(R.drawable.sldemenu_head, "shark", "浮云"));
		itemList.add(new PopMenuItem(R.drawable.menu_vip, "vip"));
		itemList.add(new PopMenuItem(R.drawable.menu_nearby, "附近消息"));
		itemList.add(new PopMenuItem(R.drawable.menu_checktime, "签到"));
		itemList.add(new PopMenuItem(R.drawable.subset, "设置"));
		itemList.add(new PopMenuItem(R.drawable.submsg, "消息"));
	}

	/**
	 * 弹出 menu item的popupwindow
	 */
	public void initPopWindow() {
		if (itemList.size() <= 2) {
			initPopData();
		}

		popMenuAdapter = new PopupMenuAdapter(this, itemList);
		View popView = LayoutInflater.from(this).inflate(
				R.layout.acy_actionbarmenu, null);
		popWind = new PopupWindow(popView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);
		// 使其聚集,可以点击里面的组件
		popWind.setFocusable(true);
		// 设置允许在外点击消失
		popWind.setOutsideTouchable(true);
		// 点击back也能消失
		popWind.setBackgroundDrawable(new BitmapDrawable());
		// 状态栏的高度
		Rect frame = new Rect();
		getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
		int statusBarHeight = frame.top;
		popWind.showAtLocation(popView, Gravity.RIGHT | Gravity.TOP, 20,
				mactionBar.getHeight() + statusBarHeight);

		popListView = (ListView) popView.findViewById(R.id.lv_acbarmenu);
		popListView.setAdapter(popMenuAdapter);
		popListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int pos,
					long arg3) {
				// TODO Auto-generated method stub

				// 设置
				if (4 == pos) {
					intent = new Intent(Main.this, Setting.class);
					startActivity(intent);
				}
			}
		});

	}


注意:

      其实,这个只能算是个自定义popupwindow的例子,对于微信的那种menu item,一直以为是actionbar的item,后来才发觉不是那么回事。为此,我费了很久的时间去琢磨着改变actionbar的组件来达到效果,当然没成功,呵呵。

      写这样的核心代码,就当是给自己的教训吧。 

  

你可能感兴趣的:(ListView)