Android-defined dialog

Source: Internet
Author: User

Android-defined dialog

For some special dialog, we want to define some special styles by ourselves. At this time, if we use some functions specified by dialog, we cannot meet our needs, at this time, we need to customize the dialog. Now this example is searched from stackoverflow and is the basis for custom dialog. If you want to customize other styles, you can modify them on this basis, below I will post the source code of this custom code:

Custom_dialog.xml:

 


  
      
       
    
     
    
   
      
CustomDialog. java:

 

 

public class CustomDialogClass extends Dialog implements    android.view.View.OnClickListener {  public Activity c;  public Dialog d;  public Button yes, no;  public CustomDialogClass(Activity a) {    super(a);    // TODO Auto-generated constructor stub    this.c = a;  }  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    requestWindowFeature(Window.FEATURE_NO_TITLE);    setContentView(R.layout.custom_dialog);    yes = (Button) findViewById(R.id.btn_yes);    no = (Button) findViewById(R.id.btn_no);    yes.setOnClickListener(this);    no.setOnClickListener(this);  }  @Override  public void onClick(View v) {    switch (v.getId()) {    case R.id.btn_yes:      c.finish();      break;    case R.id.btn_no:      dismiss();      break;    default:      break;    }    dismiss();  }}
Call your customized dialog:

 

 

R.id.TXT_Exit:CustomDialogClass cdd=new CustomDialogClass(Values.this);cdd.show();  

 

 

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.