Android override dialog box AlertDialog

Source: Internet
Author: User

--- 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
 

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.