Package com.example.dialog5;
Import Android.os.Bundle;
Import android.app.Activity;
Import Android.app.AlertDialog;
Import Android.app.Dialog;
Import Android.content.Context;
Import Android.content.DialogInterface;
Import Android.view.LayoutInflater;
Import Android.view.Menu;
Import Android.view.View;
public class Mainactivity extends Activity {
@Override
protected void onCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
//Get custom view
Layoutinflater Layoutinflator = Layoutinflater.from (this);
View MyLoginView = layoutinflator.inflate (R.layout.login, NULL);
Dialog mydialog = new Alertdialog.builder (mainactivity.this)
. Settitle ("login")
. SetIcon (r.drawable.ic_ Launcher)
. Setview (MyLoginView)
. Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
@ Override
public void OnClick (Dialoginterface dialog, int which) {
//TODO auto-generated method stub
};
})
. Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
@Override
public void OnClick ( Dialoginterface dialog, int which) {
//TODO auto-generated method stub
}
})
. Create ();
Mydialog.show ();
}
@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;
}
}
Android Custom View dialog box