Tenth chapter, Popupwindow simple Demo (Android)

Source: Internet
Author: User

Package Com.example.popupwindowdemo01;import Android.app.activity;import Android.graphics.color;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.ViewGroup ; Import Android.widget.button;import Android.widget.linearlayout;import Android.widget.popupwindow;import Android.widget.textview;public class Mainactivity extends Activity implements Onclicklistener {private Button Main_ button, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//Note the original layout// Setcontentview (R.layout.activity_main);//Instantiate layout linearlayout llayout = new LinearLayout (this);// Set layout Direction llayout.setorientation (linearlayout.vertical);//Add to Activity This.setcontentview (llayout);//Instantiate button Main_ button = New button (this),///Set button text Main_button.settext ("Show Popu"),//Add buttons to layout Llayout.addview (Main_button);// Add Click event Main_button.setonclicklistener (this) for the button;} @Overridepublic void OnClick (View arg0) {//TODO auto-generated method stub//instantiation OneTextviewtextview v = new TextView (this);///NOTE: Make sure that the view has a high width, or you can set the text so that the view passive settings aspect//can also be manually written v.setheight (50); v.setwidth ); V.settext ("I am a button"); V.setbackgroundcolor (color.green);//Instantiate popupwindow//the first parameter in this is a view, As long as the view and has a high width can//two, three parameters is popupwindow high width, not the first parameter view of the high width popupwindow pp = new Popupwindow (V, viewgroup.layoutparams.match_parent,viewgroup.layoutparams.wrap_content), or//appears under the button, can be set other position Pp.showasdropdown ( Main_button);}}

Run:




Tenth chapter, Popupwindow simple Demo (Android)

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.