Android AlertDialog 获取PositiveButton的控制权
2014-04-23 08:49
399 查看
final AlertDialog.Builder alert = new AlertDialog.Builder(
CloudSyncActivity.this);
alert.setIcon(getResources().getDrawable(R.drawable.about));
alert.setTitle("标题");
alert.setMessage("输入提示信息");
alert.setPositiveButton("确认",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
//控制点击按钮不消失问题
try
{
Field field = dialog.getClass()
.getSuperclass().getDeclaredField(
"mShowing" );
field.setAccessible( true );
// 将mShowing变量设为false,表示对话框已关闭
field.set(dialog, false );
dialog.dismiss();
}
catch (Exception e)
{
}
//获取按钮对象
Button PositiveButton=((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE);
//对按钮进行操作
PositiveButton.setVisibility(View.GONE);
}
});
alert.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
try
{
Field field = dialog.getClass()
.getSuperclass().getDeclaredField(
"mShowing" );
field.setAccessible( true );
// 将mShowing变量设为false,表示对话框已关闭
field.set(dialog, true );
dialog.dismiss();
}
catch (Exception e)
{
}
}
});
alert.show();
CloudSyncActivity.this);
alert.setIcon(getResources().getDrawable(R.drawable.about));
alert.setTitle("标题");
alert.setMessage("输入提示信息");
alert.setPositiveButton("确认",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
//控制点击按钮不消失问题
try
{
Field field = dialog.getClass()
.getSuperclass().getDeclaredField(
"mShowing" );
field.setAccessible( true );
// 将mShowing变量设为false,表示对话框已关闭
field.set(dialog, false );
dialog.dismiss();
}
catch (Exception e)
{
}
//获取按钮对象
Button PositiveButton=((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE);
//对按钮进行操作
PositiveButton.setVisibility(View.GONE);
}
});
alert.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
try
{
Field field = dialog.getClass()
.getSuperclass().getDeclaredField(
"mShowing" );
field.setAccessible( true );
// 将mShowing变量设为false,表示对话框已关闭
field.set(dialog, true );
dialog.dismiss();
}
catch (Exception e)
{
}
}
});
alert.show();
相关文章推荐
- Android AlertDialog 获取PositiveButton的控制权
- android获取自定义布局的alertdialog中edittext的值
- android下spinner值的修改以及alertDialog值的获取
- xamarin android alertdialog详解
- Android笔记:Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- android AlertDialog布局 ——2
- Android: 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框,禁止按[返回键]或[搜索键]关闭
- android alertdialog设置圆角
- Android AlertDialog之七十二变
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
- Android常用控件之AlertDialog
- Android 获取栈顶activity并在service 中弹出全局dialog解决方法
- android开发之AlertDialog点击按钮之后不消失
- Android alertdialog的按钮点击后不消失
- Android中的对话框AlertDialog使用技巧合集
- android开发-使用Dialog AlertDialog
- Android alertdialog的按钮点击后不消失
- Android对话框 (AlertDialog & ProgressDialog)
- Android控件之AlertDialog-单选、多选信息列表弹出框
- Android笔记之AlertDialog使用