Use popupwindow in Android

Source: Internet
Author: User
Tags exit in

Use popupwindow in Android.

Popupwindow will block the dialog box, and you need to exit in the external thread or popupwindow itself.

The layout design of mypopwindow. XML is as follows.

<? 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 = "#259" Android: orientation = "vertical"> <textview Android: Id = "@ + ID/textview1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "here is pop window"/> <button Android: Id = "@ + ID/button1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "OK"/> <button Android: Id = "@ + ID/button2" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "cancle"/> </linearlayout>

Mainactivity. Java file.

Click the button in mainactivity, and popupwindow is displayed.

 private void showpopwindow (context, view parent) {layoutinflater Inflater = (layoutinflater) context. getsystemservice (context. layout_inflater_service); final view vpopwindow = Inflater. inflate (R. layout. mypopwindow, null, false); // 300 wide and 300 high final popupwindow popwindow = new popupwindow (vpopwindow, 300,300, true); button okbutton = (button) vpopwindow. findviewbyid (R. id. button1); okbutton. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubtoast. maketext (mainactivity. this, "you click OK", toast. length_short ). show () ;}}); button canclebutton = (button) vpopwindow. findviewbyid (R. id. button2); canclebutton. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubpopwindow. dismiss (); // close the pop window}); popwindow. showatlocation (parent, gravity. center, 0, 0) ;}

As shown in the following figure: It is shown in the end. Here I just cut some pictures.

Click OK to display your click OK information. Click Cancel to close the popupwindow.

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.