Finally:
Main. xml layout File
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" Android: Id = "@ + ID/mainlayout"> <br/> <textview Android: layout_width = "fill_parent" Android: id = "@ + ID/textview1" <br/> Android: layout_height = "wrap_content" Android: text = "welcome information"/> <br/> <button Android: TEXT = "click the pop-up dialog box" Android: Id = "@ + ID/button1" <br/> Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> </button> <br/> </linearlayout> <br/>
Popup. xml layout File
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "match_parent" Android: layout_height = "match_parent" <br/> Android: orientation = "vertical"> <br/> <edittext Android: text = "edittext" Android: Id = "@ + ID/edittext1" <br/> Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> </edittext> <br/> <linearlayout Android: layout_width = "match_parent" <br/> Android: layout_height = "wrap_content" Android: Id = "@ + ID/linearlayout1"> <br/> <button Android: text = "OK" Android: id = "@ + ID/button1_sure" <br/> Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> </button> <br/> <button Android: TEXT = "cancel" Android: Id = "@ + ID/button2_cancel" <br/> Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> </button> <br/> </linearlayout> <br/>
Activity Code:
Package cn.com. chenzheng_java; </P> <p> Import android. app. activity; <br/> Import android. graphics. color; <br/> Import android. OS. bundle; <br/> Import android. text. inputtype; <br/> Import android. view. layoutinflater; <br/> Import android. view. view; <br/> Import android. view. view. onclicklistener; <br/> Import android. view. windowmanager. layoutparams; <br/> Import android. widget. button; <br/> Import android. widge T. edittext; <br/> Import android. widget. popupwindow; <br/> Import android. widget. textview; </P> <p> public class test1 extends activity {<br/> textview; <br/> button; </P> <p> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> button = (button) findviewbyid (R. id. button1); <br/> textview = (textvie W) findviewbyid (R. id. textview1); <br/> button. setonclicklistener (New onclicklistener () {</P> <p> @ override <br/> Public void onclick (view v) {<br/> initpopwindow (); </P> <p >}< br/> }); <br/>}</P> <p>/** <br/> * Create a popupwindow dialog box. popupwindow is a blocking pop-up box, this means that the program will wait until we exit the pop-up box. <br/> * this is different from alertdialog. The alertdialog is a non-blocking pop-up box, other things can be done in the background. <Br/> */<br/> private void initpopwindow () {<br/> // load the layout file of popupwindow <br/> View contentview = layoutinflater. from (getapplicationcontext () <br/>. inflate (R. layout. popup, null); <br/> // set the background color of popupwindow <br/> contentview. setbackgroundcolor (color. red); <br/> // declare a pop-up box <br/> final popupwindow = new popupwindow (<br/> findviewbyid (R. id. mainlayout), 200,300); <br/> // set a custom layout for the pop-up box <br/> popu Pwindow. setcontentview (contentview); </P> <p> final edittext = (edittext) contentview. findviewbyid (R. id. edittext1); <br/> // set the input box that appears when you click edittext. The default value here is the number input. At this time, you will find that you cannot enter non-numbers. <br/> edittext. setinputtype (inputtype. type_class_number); <br/>/* <br/> * This popupwindow. setfocusable (true); it is very important. If you do not add this statement before the pop-up, you will be miserable to find that you cannot input anything in <br/> * edittext. This method can set the popupwindow's ability to get the focus. When it is set to true, the system will capture the component on popupwindow <br/>. The default value is false. This method must be called before the pop-up dialog box. <Br/> */<br/> popupwindow. setfocusable (true); <br/>/* <br/> * popupwindow. the showasdropdown (view) dialog box is located next to the view component <br/> * showasdropdown (view anchor, int xoff, int yoff, x y represents the offset <br/> * showatlocation (view parent, int gravity, int X, int y) dialog Box <br/> * parent layout gravity depends on the parent layout, for example, gravity. center x y coordinate value <br/> */<br/> popupwindow. showasdropdown (button); </P> <p> button button_sure = (button) contentview. findviewbyid (R. id. button1_sure); <br/> button_sure.setonclicklistener (New onclicklistener () {<br/> @ override <br/> Public void onclick (view v) {<br/> popupwindow. dismiss (); <br/> textview. settext ("display information:" + edittext. gettext (); <br/>}< br/>}); </P> <p> button button_cancel = (button) contentview. findviewbyid (R. id. button2_cancel); <br/> button_cancel.setonclicklistener (New onclicklistener () {<br/> @ override <br/> Public void onclick (view v) {<br/> popupwindow. dismiss (); <br/>}< br/>}); </P> <p >}</P> <p>}
-------------------------------------------------------
|
In Android, The inputtype attribute plays an important role in the style of the virtual keyboard started when the edittext value is input. This greatly facilitates operations. Sometimes the virtual keyboard is only a character or a number. Therefore, inputtype is particularly important.
<Edittext Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: inputtype = "phone"/>
// Text type, mostly uppercase, lowercase, and numeric characters.
Android: inputtype = "NONE"
Android: inputtype = "text"
Android: inputtype = "textcapcharacters"
Android: inputtype = "textcapwords"
Android: inputtype = "textcapsentences"
Android: inputtype = "textautocorrect"
Android: inputtype = "textautocomplete"
Android: inputtype = "textmultiline"
Android: inputtype = "textimemultiline"
Android: inputtype = "textnosuggestions"
Android: inputtype = "texturi"
Android: inputtype = "textemailaddress"
Android: inputtype = "textemailsubject"
Android: inputtype = "textmediamessage"
Android: inputtype = "textlongmessage"
Android: inputtype = "textpersonname"
Android: inputtype = "textpostaladdress"
Android: inputtype = "textpassword"
Android: inputtype = "textvisiblepassword"
Android: inputtype = "textwebedittext"
Android: inputtype = "textfilter"
Android: inputtype = "textphonetic"
// Numeric type
Android: inputtype = "Number"
Android: inputtype = "numbersigned"
Android: inputtype = "numberdecimal"
Android: inputtype = "phone" // dial-up keyboard
Android: inputtype = "datetime"
Android: inputtype = "date" // Date keyboard
Android: inputtype = "time" // time keyboard |