对于Android的初学者,最头疼的就是弹什么样式的popwindow,Dialog之类的,特别让人心烦,activity那些东西还没搞懂,又要搞这些
所以我给大家提供我自己写的popwindow
public void showPopupWindow() { View mPopunwindwow = LayoutInflater.from(getContext()).inflate(R.layout.popup_share, null); popupWindow = new PopupWindow(mPopunwindwow, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, true); popupWindow.setContentView(mPopunwindwow); TextView sina = (TextView) mPopunwindwow.findViewById(R.id.share_sina); TextView qq = (TextView) mPopunwindwow.findViewById(R.id.share_qq); TextView zone = (TextView) mPopunwindwow.findViewById(R.id.share_zone); TextView wechat = (TextView) mPopunwindwow.findViewById(R.id.share_wechat); TextView friend = (TextView) mPopunwindwow.findViewById(R.id.share_friend); TextView link = (TextView) mPopunwindwow.findViewById(R.id.share_link); sina.setOnClickListener(this); qq.setOnClickListener(this); zone.setOnClickListener(this); wechat.setOnClickListener(this); friend.setOnClickListener(this); link.setOnClickListener(this); lp = AppApplication.getActivity().getWindow().getAttributes(); lp.alpha = 0.7f; AppApplication.getActivity().getWindow().setAttributes(lp); ColorDrawable dw = new ColorDrawable(); popupWindow.setBackgroundDrawable(dw); View rootview = LayoutInflater.from(getContext()).inflate(R.layout.news_item_foot1, null); popupWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0); popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { lp = AppApplication.getActivity().getWindow().getAttributes(); lp.alpha = 1f; AppApplication.getActivity().getWindow().setAttributes(lp); } }); }
popwindow、Dialog都是依附在一个view上的,比如:activity,fragment,只要是一个view上就行,有什么不明白的随时问我