AlertDialog是谷歌自带的一款很好用而且很漂亮的弹框,但是最近在做项目时遇到一个问题。
AlertDialog不论点击“取消”按钮或者”确定“按钮都会消失,这是很不科学的,因为如果要登录账号密码的时候,
没有填写,点击确定的时候时不能消失的,解决办法也是看了网上大神的,自己在复读一边,另外还有AlertDialog的字体
大小设置和背景设置
首先
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog alertDialog = builder.show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(30); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (TextUtils.isEmpty(name.getText()) || TextUtils.isEmpty(pwd.getText())) { Toast.makeText(context, "请输入账号和密码", Toast.LENGTH_SHORT).show(); return; } loginService(name.getText().toString(),pwd.getText().toString(),alertDialog); } });
要先show出来,拿到对象,然后获取按钮可以设置按钮的字体大小和点击事件,这样就不会点击任意按钮就会消失了
View viewById = alertDialog.getDelegate().findViewById(android.support.v7.appcompat.R.id.parentPanel); viewById.setBackgroundColor(getResources().getColor(R.color.hybg));
这个是设置dialog的背景的,ok以后博客后面多记录一点吧。。。