Android AlertDialog 获取PositiveButton的控制权
2014-01-14 10:16
351 查看
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下spinner值的修改以及alertDialog值的获取
- android获取自定义布局的alertdialog中edittext的值
- Android开发之Buidler模式初探结合AlertDialog.Builder讲解
- 【转载】android AlertDialog
- 25、Android之AlertDialog使用
- Android学习小Demo(15)一个自定义AlertDialog的实现
- 0827Android基础Toast+AlertDialog
- android-如何关闭AlertDialog.Builder对话框
- JavaAndAndroid程序学习之——关闭程序和AlertDialog中的button区别
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
- Android AlertDialog 设置setSingleChoiceItems不显示列表的原因【setMessage和setSingleChoiceItems不能同时使用】
- C#开发android之alertdialog用法
- Android AlertDialog实现半透明的弹窗
- Android AlertDialog 详解
- Android 在AlertDialog里添加布局控件
- Android service里面启动activity和alertdialog .
- android漂亮的对话框项目sweet-alert-dialog
- 完全自定义Android对话框AlertDialog的实现
- android之AlertDialog