android custom alertdialog programmatically
private void callAlert(String pw) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("비밀번호 확인")
.setMessage("입력한 비밀번호로 등록하시겠습니까?")
.setPositiveButton("확인", (dialog, which) -> {
Toast.makeText(getContext(), "등록이 완료되었습니다.", Toast.LENGTH_SHORT).show();
dialog.cancel();
dismiss();
})
.setNegativeButton("취소", (dialog, which) -> {
dialog.cancel();
});
AlertDialog dialog = builder.create();
dialog.show();
// 메시지 내용
TextView mTvMessage = dialog.findViewById(android.R.id.message);
// 폰트 변경
mTvMessage.setTypeface(tf);
// 확인 / 취소 버튼
Button btnPositive = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button btnNegative = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
// weight 조절
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) btnPositive.getLayoutParams();
layoutParams.weight = 10;
btnPositive.setLayoutParams(layoutParams);
btnNegative.setLayoutParams(layoutParams);
// 취소 버튼 margin End 값 조절
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) btnNegative.getLayoutParams();
lp.setMarginEnd(30);
}
'Before 2022 > Android' 카테고리의 다른 글
Kotlin + Retrofit2 + Okhttp3을 활용한 REST API 기본 메소드 작성 (0) | 2020.07.16 |
---|---|
AndroidX의 Android Security를 활용한 SharedPreferences 암호화 (0) | 2020.07.16 |
안드로이드 주소록에서 전화번호 가져오기 (0) | 2019.07.11 |
안드로이드 공유하기(기본 시스템) (0) | 2019.07.11 |
Floating Action Button 활용하기 (0) | 2019.07.11 |