일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 연결리스트
- android java
- BAEKJOON
- Android
- storyboard
- label
- 보호와 보안
- xocde
- C언어
- swift baekjoon
- 안드로이드
- 커스텀팝업
- text to speech
- 플러터
- Firebase
- 예외처리
- 자바
- 백준
- Android Studio
- 안드로이드스튜디오
- TextField
- Xcode
- deeplink
- IOS
- FLUTTER
- customPopup
- Swift
- 링크드리스트
- 준코딩
- 버블정렬
Archives
- Today
- Total
준코딩
커스텀 팝업 생성하기 / CustomDialog 본문
결과 이미지
1. CustomOneDialog Class 파일을 생성해주세요.
package com.example.android.me;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.fragment.app.DialogFragment;
public class CustomOneDialog extends DialogFragment {
private String title;
private String description;
private String positiveBtnText;
private CustomOneDialogListener listener;
public CustomOneDialog() {}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public void setPositiveBtnText(String text) {
this.positiveBtnText = text;
}
public void setBtnClickListener(CustomOneDialogListener listener) {
this.listener = listener;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.dialog_one_custom, container, false);
setCancelable(false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
View view = getView();
if (view != null) {
TextView titleTextView = view.findViewById(R.id.text_title);
titleTextView.setText(title);
TextView descriptionTextView = view.findViewById(R.id.text_description);
descriptionTextView.setText(description);
Button positiveButton = view.findViewById(R.id.btn_positive);
positiveButton.setText(positiveBtnText);
positiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
if (listener != null) {
listener.onClickPositiveBtn();
}
}
});
}
}
public interface CustomOneDialogListener {
void onClickPositiveBtn();
}
public static class CustomOneDialogBuilder {
private CustomOneDialog dialog = new CustomOneDialog();
public CustomOneDialogBuilder setTitle(String title) {
dialog.setTitle(title);
return this;
}
public CustomOneDialogBuilder setDescription(String description) {
dialog.setDescription(description);
return this;
}
public CustomOneDialogBuilder setPositiveBtnText(String text) {
dialog.setPositiveBtnText(text);
return this;
}
public CustomOneDialogBuilder setBtnClickListener(CustomOneDialogListener listener) {
dialog.setBtnClickListener(listener);
return this;
}
public CustomOneDialog create() {
return dialog;
}
}
}
2. dialog_one_custom.xml 파일을 생성해주세요. (저는 폰트를 따로 다운받아서 사용했습니다. 따로 폰트가 없으신 분은 fontFamily 코드 지우고 하시면 됩니다.)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20dp">
<TextView
android:id="@+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="24sp"
android:fontFamily="@font/jalnan"
tools:text="타이틀" />
<TextView
android:id="@+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:textAlignment="center"
android:paddingHorizontal="10dp"
android:textColor="#000000"
android:textSize="16sp"
android:fontFamily="@font/omyupretty"
tools:text="설명" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_positive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#B266FF"
android:textColor="@android:color/white"
android:textStyle="bold"
tools:text="확인" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
3. 사용 하실때 아래처럼 생성하여서 사용하시면 됩니다!
CustomOneDialog.CustomOneDialogBuilder builder = new CustomOneDialog.CustomOneDialogBuilder();
builder.setTitle("알림")
.setDescription("네트워크 연결 상태를 확인해주세요.")
.setPositiveBtnText("확인")
.setBtnClickListener(new CustomOneDialog.CustomOneDialogListener() {
@Override
public void onClickPositiveBtn() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask();
}
}
});
CustomOneDialog dialog = builder.create();
dialog.show(getSupportFragmentManager(), "custom_one_dialog");
'프로그래밍 > Android(JAVA)' 카테고리의 다른 글
GPS를 이용하여 현재 주소 구하기.(Android Java) (0) | 2023.06.28 |
---|---|
핑거푸시 연동하기 (FingerPush Android) (0) | 2023.06.26 |
파이어베이스 다이나믹링크 Android13 버전 에러 (0) | 2023.06.26 |
Pull to Refresh 당겨서 새로고침 (0) | 2023.04.26 |
Android(java) 앱 버전 업데이트 빌드 에러[The destination foler does not exist or is not writeable] (2) | 2023.04.05 |
Comments