Step by Step _android Development Course [26]_ User interface Popupwindow (pop-up window)

Source: Internet
Author: User

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

    • Topic: User Interface Popupwindow (pop-up window)
      -

The difference between Popupwindow and Alertdialog:

Alertdialog is non-blocking: Alertdialog pop-up, backstage can also do things.

Popupwindow is blocking: only allow us to operate the Popupwindow before Popupwindow exits, other operations are blocked.

Popupwindow (example):

Define a layout for Popupwindow.
Popupwindow.xml:

<?xml version= "1.0" encoding= "Utf-8"?><linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  android:layout_width  =" fill_parent " android:layout_height  =" fill_parent " android:background  =" #336699 " android:orientation  = "vertical" ;     <imageview  android:id
      = "@+id/imageview"  android:layout_width  = "wrap_content"  android:layout_height  = "wrap_content"  android:src  =  "@drawable/myimage" />     <linearlayout  android:id  = "@+id/linearlayout1"  android:layout_width< /span>= "wrap_content"  android:layout_height  = "wrap_content"  android:orientation  = "vertical" ;         <button  android:id= "@+id/button1_sure"  android:layout_width  =             "wrap_content"   android:layout_height  = "wrap_content"  android:text  = "OK" />         <button android:id= "@+id/button2_cancel"android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "android:text=" Cancel " /&G t;                                         </linearlayout></linearlayout>

Mainactivity.java:

Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.text.InputType;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView;ImportAndroid.widget.PopupWindow;ImportAndroid.widget.TextView; Public  class mainactivity extends Activity {Button button;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        Button = (button) Findviewbyid (R.id.button1); Button.setonclicklistener (NewOnclicklistener () {@Override             Public void OnClick(View arg0) {//TODO auto-generated method stubInitpopwindow ();    }               }); }Private void Initpopwindow() {//Load the Popupwindow layout fileView Contentview = Layoutinflater.from (Getapplicationcontext ()). Inflate (R.layout.popupwindow,NULL);//Declaration Popupwindow Pop-up windowPopupwindow Popupwindow =NewPopupwindow (NULL, -, -); Popupwindow.setcontentview (Contentview);//Get FocusPopupwindow.setfocusable (true);/** * Popupwindow Three display methods: * Showasdropdown (view view) Pop-up dialog box, located next to the View component Showasdropdown (view anchor, int x, int y) pops up the dialog box, positioned next to the view component, X y for offset showatlocation (View parent, int gravity, int x, int y) Popup dialog, position X y represents the offset, relative to the location of the parent layout * /Popupwindow.showasdropdown (button);        ImageView ImageView = (ImageView) Contentview.findviewbyid (R.id.imageview);        Button button_sure = (button) Contentview.findviewbyid (r.id.button1_sure);    Button Button_cancel = (button) Contentview.findviewbyid (R.id.button2_cancel); }}

Operation Result:

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

Step by Step _android Development Course [26]_ User interface Popupwindow (pop-up window)

Related Article

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.