Android中自定义对话框的实现
public class MainActivity extends Activity implements OnClickListener{private Dialog mDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); creatDialog(); } private void creatDialog(){ View view = this.getLayoutInflater().inflate(R.layout.login, null); Button close = (Button) view.findViewById(R.id.close); Button login = (Button) view.findViewById(R.id.login_confirm); Button regsiter = (Button) view.findViewById(R.id.login_cancel); close.setOnClickListener(this); login.setOnClickListener(this); regsiter.setOnClickListener(this); mDialog = new Dialog(this,R.style.dialog); mDialog.setContentView(view); mDialog.show(); }@Overridepublic void onClick(View v) { switch (v.getId()) {case R.id.close:mDialog.dismiss();break;case R.id.login_confirm:Toast.makeText(this, "登陆", Toast.LENGTH_SHORT).show();break;case R.id.login_cancel:Toast.makeText(this, "注册", Toast.LENGTH_SHORT).show();break;}}}?