本文主要是介绍android 自定义alertdialog和取消dialog,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
亲测可用,若有疑问请私信
看代码:
public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);LayoutInflater inflater = getLayoutInflater();View view1 = inflater.inflate(R.layout.alert, (ViewGroup) findViewById(R.id.alertdialog));builder.setView(view1);final AlertDialog dialog = builder.show();view1.findViewById(R.id.btn_invent).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Log.e("tag", "onClick: "+"点击取消" );dialog.dismiss();}});}});} }要取消dialog先要获取dialog,再dismiss(),直接dismiss()是没有用的; demo下载地址:https://github.com/renjiemei1225/AlertDialogTest2
这篇关于android 自定义alertdialog和取消dialog的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!