Code-only implementation dialog box

Source: Internet
Author: User

Dialog Box customization: Java code implementation of relative Layout
Create alertdiaglog

Window window = DLG. getwindow ()

Create layout. The code is relative layout.

Load layout, load related space, and set the location of related controls

The Code is as follows:

Int bgimageviewid = 10; int iconimageviewid = 11; int textviewid = 12; int buttonokid = 13; int buttoncancelid = 14; int srcimageviewid = 15; Final alertdialog DLG = new alertdialog. builder (this ). create (); DLG. show (); window = DLG. getwindow (); // This effect is mainly implemented here. relativelayout rlayout = new relativelayout (this); // set the background imageview bg_iv = new imageview (this); bg_iv.setid (bgimageviewid); bg_iv.setimageresource (R. drawable. bg2); relativelayout. layoutparams bgrelativeparams_iv = new relativelayout. layoutparams (viewgroup. layoutparams. wrap_content, viewgroup. layoutparams. wrap_content); bgrelativeparams_iv.addrule (relativelayout. center_horizontal); rlayout. addview (bg_iv, bgrelativeparams_iv); imageview icon_iv = new imageview (this); icon_iv.setid (iconimageviewid); icon_iv.setimageresource (R. drawable. egame_logo_icon); relativelayout. layoutparams iconrelativeparams_iv = new relativelayout. layoutparams (viewgroup. layoutparams. wrap_content, viewgroup. layoutparams. wrap_content); iconrelativeparams_iv.addrule (relativelayout. align_left, bgimageviewid); iconrelativeparams_iv.addrule (relativelayout. align_top, bgimageviewid); rlayout. addview (icon_iv, iconrelativeparams_iv); textview TV = new textview (this); TV. setid (textviewid); TV. settext ("xxxxxx"); relativelayout. layoutparams relativeparams_ TV = new relativelayout. layoutparams (viewgroup. layoutparams. wrap_content, viewgroup. layoutparams. wrap_content); relativeparams_ TV .addrule (relativelayout. center_horizontal, iconimageviewid); rlayout. addview (TV, relativeparams_ TV); imageview src_iv = new imageview (this); src_iv.setid (srcimageviewid); src_iv.setbackgroundresource (R. drawable. app_icon); relativelayout. layoutparams srcrelativeparams_iv = new relativelayout. layoutparams (viewgroup. layoutparams. wrap_content, viewgroup. layoutparams. wrap_content); srcrelativeparams_iv.addrule (relativelayout. center_in_parent, bgimageviewid); // relativeparams_ TV .addrule (relativelayout. align_top, bgimageviewid); rlayout. addview (src_iv, srcrelativeparams_iv); button btn_ OK = new button (this); btn_ OK .setid (buttonokid); btn_ OK .setbackgroundresource (R. drawable. submit); relativelayout. layoutparams relativeparams_btn_ OK = new relativelayout. layoutparams (viewgroup. layoutparams. wrap_content, viewgroup. layoutparams. wrap_content); // relativelayout. layoutparams Params = (relativelayout. layoutparams) iv. getlayoutparams (); relativeparams_btn_ OK .addrule (relativelayout. align_bottom, bgimageviewid); relativeparams_btn_ OK .addrule (relativelayout. align_left, bgimageviewid); rlayout. addview (btn_ OK, relativeparams_btn_ OK); button btn_cancel = new button (this); btn_cancel.setid (buttoncancelid); btn_cancel.setbackgroundresource (R. drawable. cancel); relativelayout. layoutparams relativeparams_btn_cancel = new relativelayout. layoutparams (viewgroup. layoutparams. wrap_content, viewgroup. layoutparams. wrap_content); relativeparams_btn_cancel.addrule (relativelayout. align_bottom, bgimageviewid); relativeparams_btn_cancel.addrule (relativelayout. align_right, bgimageviewid); rlayout. addview (btn_cancel, relativeparams_btn_cancel); // window. setcontentview (R. layout. DIAG); window. setcontentview (rlayout); // Add an event for the confirmation button and execute the exit Application Operation btn_ OK .setonclicklistener (new view. onclicklistener () {public void onclick (view v) {}}); // close alert dialog framework btn_cancel.setonclicklistener (new view. onclicklistener () {public void onclick (view v) {DLG. cancel ();}});

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.