Android custom dialog box, android custom

Source: Internet
Author: User

Android custom dialog box, android custom

Effect of the custom dialog box for Android:

Core code:

Package com. example. diydialog; import android. OS. bundle; import android. app. activity; import android. app. alertDialog; import android. content. dialogInterface; import android. content. dialogInterface. onClickListener; import android. view. menu; import android. view. view; import android. widget. editText; import android. widget. toast; public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main) ;}@ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true;} public void btn_dialog (View v) {AlertDialog. builder builder = new AlertDialog. builder (this); builder. setTitle ("User Logon"); builder. setIcon (R. drawable. ic_launcher); final View view = getLayoutInflater (). inflate (R. layout. login, null); builder. setView (view); builder. setPositiveButton ("login", new OnClickListener () {@ Override public void onClick (DialogInterface arg0, int arg1) {// The method automatically generated by TODO to view EditText ed1 = (EditText. findViewById (R. id. editText1); EditText ed2 = (EditText) view. findViewById (R. id. editText2); String ed11 = ed1.getText (). toString (); String ed22 = ed2.getText (). toString (); Toast. makeText (MainActivity. this, ed11 + "---" + ed22, Toast. LENGTH_SHORT ). show () ;}}); builder. setNegativeButton ("cancel", new OnClickListener () {@ Override public void onClick (DialogInterface arg0, int arg1) {// TODO automatically generated method stub Toast. makeText (MainActivity. this, "canceled", Toast. LENGTH_SHORT ). show () ;}}); builder. show ();}}

The layout file is relatively simple and will not be pasted out. You can add corresponding buttons and text boxes according to the code.

Related Article

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.