每个 popupWindow都 有一个view,把view.setAlpha(0.5f);即可.
public class CustomActionProvider extends ActionProvider implements OnMenuItemClickListener, OnClickListener, OnTouchListener, OnKeyListener { private final Context context;// 上下文 private View actionView;//action view private PopupWindow mPopupWindow;//popup window 里有个view,view显示的像个menu private View mMenu; //popup window 里的显示控件 private void initPopupMenu(){ LayoutInflater lif = LayoutInflater.from(context); mMenu = lif.inflate(R.layout.custom_popup_window, null); mMenu.setAlpha(0.5f); mPopupWindow = new PopupWindow(mMenu, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT); /* * setBackgroundDrawable很重要,没有这个函数 back键和menu键关闭popwindow 很麻烦, * 有了它以后,就不用为popwindow内的控件分别设置setOnKeyListener和setOnTouchListener了 * 可以同时支持back返回和点popwindow外面关闭popwindow, */ mPopupWindow.setBackgroundDrawable(new ColorDrawable(0x00000)); } //... }
时间: 2024-11-10 07:08:12