Custom Popupwindow two or three things

Source: Internet
Author: User

:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.