像PopupMenu在Icon的下左方一點點顯示一排Menu
試滿久終於給我試出來了。以下是程式碼。
抄東抄西,終於有一個比較像樣的了
private PopupWindow popupWindow = null;
private void initPopupWindow() { LayoutInflater layoutInflater =(LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); View popupView = layoutInflater.inflate(R.layout.popup_setting, null); popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int xOffset = -(popupView.getMeasuredWidth() - popupView.getWidth()); // 使其聚集 popupWindow.setFocusable(true); // 设置允许在外点击消失 popupWindow.setOutsideTouchable(true); //刷新状态(必须刷新否则无效) popupWindow.update(); popupWindow.showAsDropDown(btn_setting, xOffset + 70, -10); }
沒有留言:
張貼留言