Android Package implements various Styles dialog box

Source: Internet
Author: User

First


Implementation code

Package Com.jock.alertdialog;import Android.app.activity;import Android.content.context;import android.os.Bundle; Import Android.view.keyevent;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Android.view.inputmethod.inputmethodmanager;import Android.widget.EditText;import android.widget.toast;/** * Fine Imitation Iosalertviewcontroller control demo */public class Mainactivity extends Activity implements Onitemclicklistener, Ondismisslistener {private Alertview malertview;//avoid creating recurring view. First create a view, then need to show out, recommend this procedure private Alertview malertviewext;//form extension Sample private EditText etname;//expand view Content Private    Inputmethodmanager IMM;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        IMM = (Inputmethodmanager) getsystemservice (Context.input_method_service); Malertview = new Alertview ("title", "Content", "Cancel", new string[]{"OK"}, NULL, this, Alertview.        Style.alert, this). Setcancelable (True). Setondismisslistener (this); Expand Form malertviewext = new Alertview ("Prompt", "Please be in good condition for your profile.")        "," Cancel ", null, New string[]{" complete "}, this, AlertView.Style.Alert, this);        ViewGroup Extview = (viewgroup) layoutinflater.from (this). Inflate (R.layout.alertext_form,null);        Etname = (EditText) Extview.findviewbyid (r.id.etname); Etname.setonfocuschangelistener (New View.onfocuschangelistener () {@Override public void Onfocuschan                The GE (view view, Boolean focus) {///input box comes up moving up the Boolean isopen=imm.isactive (); Malertviewext.setmarginbottom (Isopen&&focus?

120:0); System.out.println (IsOpen); } }); Malertviewext.addextview (Extview); } public void AlertShow1 (view view) {malertview.show (); } public void AlertShow2 (view view) {New Alertview ("title", "content", NULL, new string[]{"OK"}, NULL, this, Alertview. Style.alert, this). Show (); public void alertShow3 (view view) {New Alertview (null, NULL, NULL, New string[]{"Highlight Button1", "Highlight Button2", "highlight Button3 "}, New string[]{" Other Button1 "," Other Button2 "," Other Button3 "," Other Button4 "," Other Button5 "," Other Button6 ", "Other button7", "Other Button8", "Other Button9", "Other Button10", "Other Button11", "Other Button12"}, this, A LertView.Style.Alert, this). Show (); } public void AlertShow4 (view view) {New Alertview ("title", NULL, "Cancel", new string[]{"Highlight Button1"}, new string[]{"its It button1 "," Other Button2 "," Other Button3 "}, this, AlertView.Style.ActionSheet, this). Show (); } public void alertShow5 (view view){New Alertview ("title", "Content", "Cancel", NULL, NULL, this, AlertView.Style.ActionSheet, this). Setcancelable (True). Show (); } public void AlertShow6 (view view) {New Alertview ("Upload Avatar", null, "Cancel", null, new string[]{"photo "," from the album select "}, this, AlertView.Style.ActionSheet, this). Show (); } public void Alertshowext (view view) {malertviewext.show (); } private void Closekeyboard () {//Off soft keyboard Imm.hidesoftinputfromwindow (Etname.getwindowtoken (), 0); Recovery position malertviewext.setmarginbottom (0); } @Override public void Onitemclick (Object o,int position) {Closekeyboard (); Infer if the form view is expanded. and click the Non-Cancel button if (o = = Malertviewext && Position! = alertview.cancelposition) {String name = et Name.gettext (). toString (); if (Name.isempty ()) {Toast.maketext (this, "Nothing is filled", toast.length_short). Show (); } else{Toast.maketext (tHis, "Hello," +name, Toast.length_short). Show (); } return; } toast.maketext (this, "clicked on" + Position + "a", Toast.length_short). Show (); } @Override public void Ondismiss (Object o) {closekeyboard (); Toast.maketext (This, "disappeared", Toast.length_short). Show (); } @Override public boolean onKeyDown (int keycode, keyevent event) {if (keycode = = Keyevent.keycode_back & amp;& Event.getrepeatcount () = = 0) {if (Malertview!=null && malertview.isshowing ()) { Malertview.dismiss (); return false; }} return Super.onkeydown (KeyCode, event); }}


Click to download source code



Android Package implements various Styles dialog box

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.