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.