Android alertdialog-Login dialog box

Source: Internet
Author: User

Step 1:

First set the login screen- dialog_login.xml : username and password input box, and Clear button and login button

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:padding= "8DP">        <TablelayoutAndroid:id= "@+id/dl_table"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:stretchcolumns= "1"android:visibility= "visible"Tools:layout_editor_absolutex= "8DP"Tools:layout_editor_absolutey= "8DP">        <TableRow>            <TextViewAndroid:layout_width= "60DP"Android:layout_height= "Wrap_content"android:gravity= "Center"Android:text= "User" />            <EditTextAndroid:id= "@+id/et_user"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" />        </TableRow>        <TableRowAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent">            <TextViewAndroid:layout_width= "60DP"Android:layout_height= "Wrap_content"android:gravity= "Center"Android:text= "Password" />            <EditTextAndroid:id= "@+id/et_password"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:inputtype= "Textpassword" />        </TableRow>    </Tablelayout>    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content">        <ButtonAndroid:id= "@+id/btn_clear"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Clear" />        <ButtonAndroid:id= "@+id/btn_login"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Login" />    </LinearLayout>

Step 2:

1. Load the Dialog_login.xml interface into the generated View object;

2. Build dialog the object and load the custom view in;

3. Display the login dialog box;

 public  class  customactivity extends   appcompatactivity {@Override  protected  void   OnCreate ( Bundle savedinstancestate) { super   = View.inflate (this , R.layout.dialog_login, null  ); Alertdialog.builder Builder  = new  alertdialog.builder (this  ). Setview (view);            Builder.show (); }}

Note: The call builder.show is equivalent to creating first AlertDialog and then displaying

This completes the Login dialog box creation, if you want to further get user input information, click the button can be manipulated, add the following code:

Android alertdialog-Login 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.