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();