AlertDialog获取Button,点击外围不消失,设置样式

private AlertDialog AlertDialogShow(String message){
    AlertDialog.Builder builder = new AlertDialog.Builder(OutScaner3Activity.this,
            android.R.style.Theme_Holo_Light_Dialog).
            setTitle("提示").setMessage(message).
            setNegativeButton("确定", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    }).setPositiveButton("取消", null);
    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);   //点击AlertDialog外面的位置,AlertDialog不消失,
    //设置背景样式
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);   
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 
    dialog.show();
    //注意放在dialog.show();的后面
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setFocusable(false);   //获取button
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setFocusable(false);  //获取button
    return dialog;
}

猜你喜欢

转载自blog.csdn.net/talinboy/article/details/72869718
今日推荐