在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的组件来达到效果,当然没成功,呵呵。

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

  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值