:
Code:
Public class viewactivity extends Activity implements View. Onclicklistener {Popupwindow Popwindow; LinearLayout Rootview;@Override protected void onCreate(Bundle savedinstancestate) {requestwindowfeature (window.feature_no_title);Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_view); Rootview = (linearlayout) Findviewbyid (R.id.ll_rootview); Initpopwindow ( This); }@Override Public void OnClick(View v) {popwindow.showatlocation (Rootview, Gravity.center,0,0); } Public void Initpopwindow(Context context) {View view = Layoutinflater.from (context). Inflate (R.layout.view_share,NULL); Popwindow =NewPopupwindow (view, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT,true); ImageView Iv_cancel = (ImageView) View.findviewbyid (r.id.iv_cancel); Iv_cancel.setonclicklistener (NewView.onclicklistener () {@Override Public void OnClick(View v) {Popwindow.dismiss (); } });//Give Popupwindow set back key to listenPopwindow.getcontentview (). Setfocusableintouchmode (true); Popwindow.getcontentview (). Setfocusable (true); Popwindow.getcontentview (). Setonkeylistener (NewView.onkeylistener () {@Override Public Boolean OnKey(View V,intKeyCode, KeyEvent event) {if(event.getaction () = = Keyevent.action_down && keycode = = keyevent.keycode_back) {if(Popwindow! =NULL&& popwindow.isshowing ()) {Popwindow.dismiss (); }return true; }return false; } }); }}
whether the background is gray:
//直接在view_share的根布局设置背景颜色就可以
android:background="#aa666666"
Custom Popupwindow two or three things