Hello, ๋๋'s world !
DialogFragment ๋ณธ๋ฌธ
์ค๋์ DialogFragment๋ฅผ ์ปค์คํ ํ๋๋ฒ์ ๋ํด ์์๋ณด๊ฒ ๋ค.
-
๋ค์ด์ผ๋ก๊ทธ๋ฅผ ๋์ธ xml ๋ ์ด์์์ ๋ฒํผ์ ๋ง๋ค์ด์ค๋ค.
-
๋ค์ด์ผ๋ก๊ทธ xml ๋ ์ด์์ ๊ตฌํ
-
DialogFragment๋ฅผ ์์๋ฐ๋ ํด๋์ค ๊ตฌํ
-
1๋ฒ์ ํ๋๊ทธ๋จผํธ์ 3๋ฒ์ ์ฐ๊ฒฐํ๋ค.
1. fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Button
android:id="@+id/f_show_btn"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Show" />
</androidx.constraintlayout.widget.ConstraintLayout>
2. dialog_receiver.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:textSize="16dp"
android:text="๋ฐ๋ ์ฌ๋"
android:background="@color/colorPrimary"/>
<Spinner
android:id="@+id/dialog_receiver"
android:layout_width="match_parent"
android:layout_height="50dp"/>
<LinearLayout
android:layout_marginTop="135dp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<Button
android:id="@+id/dialog_receiver_ok_btn"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight=".5"
android:gravity="center"
android:text="ํ์ธ"
android:textSize="16dp"
android:background="@color/colorPrimary"/>
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:background="#ffffff" />
<Button
android:id="@+id/dialog_receiver_cancle_btn"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight=".5"
android:gravity="center"
android:text="์ทจ์"
android:textSize="16dp"
android:background="@color/colorPrimary"/>
</LinearLayout>
</LinearLayout>
3. LetterReceiverDialog.java
public class LetterReceiverDialog extends DialogFragment implements View.OnClickListener {
public static final String TAG_EVENT_DIALOG = "dialog_event";
public LetterReceiverDialog(){}
public static LetterReceiverDialog getInstance(){
LetterReceiverDialog letterReceiverDialog = new LetterReceiverDialog();
return letterReceiverDialog;
}
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_receiver, container);
Spinner mSpinner = (Spinner)v.findViewById(R.id.dialog_receiver);
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.testSpinner));
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(mAdapter);
Button mOkBtn = (Button)v.findViewById(R.id.dialog_receiver_ok_btn);
Button mCancleBtn = (Button)v.findViewById(R.id.dialog_receiver_cancle_btn);
mOkBtn.setOnClickListener(this);
mCancleBtn.setOnClickListener(this);
//ํ๋ฉดํฐ์น์ ๊บผ์ง ๋ง๊ธฐ
setCancelable(false);
return v;
}
@Override
public void onClick(View v) {
dismiss();
}
//๋ค์ด์ผ๋ก๊ทธ ์ฌ์ด์ฆ ์กฐ์
@Override
public void onResume() {
super.onResume();
Window window = getDialog().getWindow();
if(window == null) return;
WindowManager.LayoutParams params = window.getAttributes();
params.width = 1000;
params.height = 1000;
window.setAttributes(params);
}
}
4. FragmentMain.java
onCreateView() ๋ฐ์ ์์ฑํด์ค๋ค.
Button mAddBtn = (Button)v.findViewById(R.id.f_show_btn);
mAddBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LetterReceiverDialog mletterReceiverDialog = LetterReceiverDialog.getInstance();
mletterReceiverDialog.show(getFragmentManager(), LetterReceiverDialog.TAG_EVENT_DIALOG);
}
});
๋ค์ด์ผ๋ก๊ทธ ์์๋ฅผ ๋์คํ๋ ์ด์ ๋น์จ์ ๋ฐ๋ผ ์ผ์ ํ ํฌ๊ธฐ๋ก ๋ง๋ค๊ณ ์ถ์๋๋ฐ ์์๋์๋ค ใ ใ
display์ x,y๊ฐ์ ๋ฐ์์ฌ์์๋ ํจ์๋ฅผ fragment์์ ๊ตฌํํด๋ณด์์ผ๊ฒ ๋ค. ( dimen ์ผ๋ก %๋ฅผ ์ค๋ณด๋ คํ์ง๋ง...ใ ใ )
์๋ฒ์ฃผ Firebase DB์ ๊ฐ๋ฃ์๋ ์๋ด์ผ๊ฒ ๋ค.
<๊ฐ๋ฐํ๊ฒฝ>
java version "1.8.0_271"
android API 10.0 (Q)
android studio "4.0.1"
<์ฐธ๊ณ >
developer.android.com/guide/topics/ui/dialogs?hl=ko
developer88.tistory.com/132
pluu.github.io/blog/rxjava/2017/02/04/android-alertdialog
rmirabelle.medium.com/how-to-set-dialogfragment-width-and-height-733c5b174178
'๐ Android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Android Waveํจ๊ณผ ๋ฃ๊ธฐ WaveView (0) | 2021.01.20 |
---|---|
Fragment์ RecyclerView ์์ Fragment๋ก ๋ฐ์ดํฐ ์ ๋ฌํ๊ธฐ (0) | 2021.01.20 |
dialogFragment ์์ Fragment ๋ก ๋ฐ์ดํฐ ์ ๋ฌ (0) | 2021.01.18 |
onDraw() ๋ฅผ ํ์ฉํ์ฌ ๊ทธ๋ฆผ๊ทธ๋ฆฌ๊ธฐ (0) | 2021.01.08 |
RecyclerView (0) | 2021.01.08 |