Customizing the Dialog dialog box

Source: Internet
Author: User

Layout file:


<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= " Android "android:orientation=" vertical "android:layout_width=" 300DP "android:layout_height=" Wrap_content "> <textview android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "User name:"/>& Lt     EditText android:id= "@+id/edtusername" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:text= ""/><textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android : text= "Password:"/><edittext android:id= "@+id/edtpassword" android:layout_width= "Fill_parent" android:layout_he ight= "Wrap_content" android:inputtype= "Textpassword" android:text= ""/><linearlayout android:orientation    = "Horizontal" android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:gravity= "center" ><button android:id= "@+id/btnOK "android:layout_width=" 160DP "android:layout_height=" wrap_content "android:text=" OK Login "/><button an    Droid:id= "@+id/btncancel" android:layout_width= "80DP" android:layout_height= "Wrap_content" android:text= "Cancel" /></linearlayout></linearlayout>


<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "    Android "android:orientation=" horizontal "android:layout_width=" Fill_parent "android:layout_height=" Fill_parent " ><linearlayout android:orientation= "vertical" android:layout_width= "0DP" android:layout_height= "Fill_par     Ent "android:layout_weight=" 1 "/><linearlayout android:orientation=" vertical "android:layout_width=" 0DP " android:layout_height= "Fill_parent" android:layout_weight= "1" ><button android:id= "@+id/btnLoginDlg" and Roid:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "Login System"/><TextView Android Oid:id= "@+id/txtresult" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= " "/></linearlayout><linearlayout android:orientation=" vertical "android:layout_width=" 0DP "Android:lay Out_height= "Fill_parent" Android: layout_weight= "1"/></linearlayout> 

Package;import;import;import android.os.bundle;import Android.view.view;import android.widget.*;p ublic class Main extends Activity {private Button mbtnlogindlg;private TextView mtxtresult;private Dialog mlogindlg;/** Called when the activity is first created.        */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.main);    Setupviewcomponent (); private void Setupviewcomponent () {Mbtnlogindlg = (Button) Findviewbyid (R.ID.BTNLOGINDLG); mtxtresult = (TextView) F    Indviewbyid (; Mbtnlogindlg.setonclicklistener (Btnlogindlgonclklis); } private Button.onclicklistener Btnlogindlgonclklis = new Button.onclicklistener () {public void OnClick (View v) {MTXTR Esult.settext (""); Mlogindlg = new Dialog (main.this);//The Dialog object established must have its owner. Mlogindlg.settitle ("Login System"); Mlogindlg.setcancelable (false);//Set the Cancelable property so that users cannot leave the dialog box by using the Back Page button MlogindlG.setcontentview (R.LAYOUT.LOGIN_DLG); Button Loginbtnok = (button) Mlogindlg.findviewbyid (; Button Loginbtncancel = (button) Mlogindlg.findviewbyid (; Loginbtnok.setonclicklistener (    Logindlgbtnokonclklis); Loginbtncancel.setonclicklistener (Logindlgbtncancelonclklis); ();}; Private Button.onclicklistener Logindlgbtnokonclklis = new Button.onclicklistener () {public void OnClick (View v) { EditText edtusername = (EditText) Mlogindlg.findviewbyid (; EditText Edtpassword = (EditText) Mlogindlg.findviewbyid (; Mtxtresult.settext ("Please enter the user name:" +    Edtusername.gettext (). ToString () + "Password:" + edtpassword.gettext (). ToString ()); Mlogindlg.cancel ();}; Private Button.onclicklistener Logindlgbtncancelonclklis = new Button.onclicklistener () {public void OnClick (View v) { Mtxtresult.settext ("You press the \ Cancel \" button.) "); Mlogindlg.cancel ();}};}


Customizing the Dialog 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: 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.