--- Xml
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: orientation = "vertical">
<LinearLayout
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center"
Android: orientation = "horizontal"
Android: padding = "2dip">
<EditText
Android: id = "@ + id/edittext1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: typeface = "monospace"
Android: width = "180dip"/>
</LinearLayout>
</LinearLayout>
------. Java
LayoutInflater inflater = LayoutInflater. from (EA6Activity. this );
Final View DialogView = inflater
. Inflate (R. layout. dialog, null );
// Merge into one sentence
View view = LayoutInflater. from (this). inflate (R. layout. ID, null );
-------- Input in AlertDialog Creation
Builder. setView (DialogView );
------------------ Rewrite
WindowManager manager = getWindowManager ();
Display display = manager
. Getdefadisplay display ();
Int width = display
. GetWidth ();
Int height = display
. GetHeight ();
LayoutInflater inflater = getLayoutInflater ();
View view = inflater
. Inflate (
R. layout. dialog,
Null );
AlertDialog alert = new AlertDialog. Builder (
DialogActivity. this)
. Create ();
Alert. show ();
Alert. getWindow ()
. SetLayout (
Width/2,
Height/4 );
Alert. setTitle ("test ");
Alert. getWindow ()
. SetContentView (
R. layout. dialog );
----------------------- Rewrite 2
Final AlertDialog dlg = new AlertDialog. Builder (
DialogActivity. this)
. Create ();
Dlg. show ();
Window window = dlg
. GetWindow ();
// *** This effect is implemented here.
// Set the content page of the window. The view content is defined in the shrew_exit_dialog.xml file.
Window. setContentView (R. layout. dialog );
--------------------- Activity
MButton1.setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
Final AlertDialog dlg = new AlertDialog. Builder (
DialogActivity. this)
. Create ();
Dlg. show ();
Window window = dlg
. GetWindow ();
Window. setContentView (R. layout. dialog );
Button button1 = (Button) window
. FindViewById (R. id. button1 );
Button1.setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (
View v ){
// TODO Auto-generated method stub
Android. OS. Process
. KillProcess (android. OS. Process
. MyPid ());
}
});
}
});
----------------------- Layout. xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: background = "@ drawable/icon1"
Android: orientation = "vertical">
<Button www.2cto.com
Android: id = "@ + id/button1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Button"/>
</LinearLayout>
By gongzibai