투케이2K

344. (AndroidStudio/android/java) [간단 소스] SweetAlert 커스텀 팝업창 라이브러리 대표 이미지 설정 및 버튼 색상 변경 본문

Android

344. (AndroidStudio/android/java) [간단 소스] SweetAlert 커스텀 팝업창 라이브러리 대표 이미지 설정 및 버튼 색상 변경

투케이2K 2022. 9. 21. 16:52
반응형

[개발 환경 설정]

개발 툴 : AndroidStudio

개발 언어 : java

 
 
 

[소스 코드]

					// TODO [sweet alert 팝업창]
					try {
						final SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(ParentActivity.this, SweetAlertDialog.CUSTOM_IMAGE_TYPE); //TODO 타입
						sweetAlertDialog.setCustomImage(R.drawable.ic_launcher); // TODO [커스텀 이미지]
						sweetAlertDialog.setTitleText(title); //TODO 제목
						sweetAlertDialog.setContentText("\n" + body + "\n"); //TODO 내용
						sweetAlertDialog.setCancelable(false); //TODO 강제 닫기 설정
						sweetAlertDialog.setConfirmText("확인"); //TODO 확인
						sweetAlertDialog.setCancelText("취소"); //TODO 취소
						sweetAlertDialog.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
							@Override
							public void onClick(SweetAlertDialog sDialog) {
								try {
									sweetAlertDialog.dismissWithAnimation();
								}
								catch (Exception e){
									e.printStackTrace();
								}
							}
						});
						sweetAlertDialog.setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
							@Override
							public void onClick(SweetAlertDialog sDialog) {
								try {
									sweetAlertDialog.dismissWithAnimation();
								}
								catch (Exception e){
									e.printStackTrace();
								}
							}
						});
						sweetAlertDialog.show();

						// [버튼 색상 커스텀 변경]
						Button okBtn = (Button) sweetAlertDialog.findViewById(R.id.confirm_button);
						okBtn.setBackgroundColor(ContextCompat.getColor(ParentActivity.this, R.color.pushColor));

						Button cancelBtn = (Button) sweetAlertDialog.findViewById(R.id.cancel_button);
						cancelBtn.setBackgroundColor(ContextCompat.getColor(ParentActivity.this, R.color.noColor));
					}
					catch (Exception ex){
						ex.printStackTrace();
					}

					// ------------------------------------------

 

반응형
Comments