๋ทฐํ์ด์ง์ผ๋ก ๋ค๋ฅธ ํ๋ฉด์ผ๋ก ๋๊ฒจ๋ ๋ค์ ํ๋ฉด์ด ๊ทธ๋๋ก ๋จ์์์
fragment ํ๊ทธ๋ name ํ๊ทธ๋ก ์ด๋ค ํ๋๊ทธ๋จผํธ๊ฐ ๋ณด์ผ์ง ์ ํด๋๋ ์ ์ ๋์ํ๊ธฐ ๋๋ฌธ์ ๋ทฐํ์ด์ง์ผ๋ก ํ๋ฉด์ ๋๊ฒผ์ ๋ ์ ๋์ด๊ฐ๊ณ ๋ค์ ํ๋ฉด์ด ๋จ์์์ ์ ์๋ค. ๊ทธ๋์ FragmentContainerView๋ฅผ ์ฌ์ฉํด ๋์ ๋์ํ๊ฒ ๋ณ๊ฒฝํด์ผ ํ๋ค.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
๋ทฐ์ ๊ด๋ จ๋ ์์
์ ํ ๋
ํ๋๊ทธ๋จผํธ์์ ๋ทฐ์ ๊ด๋ จ๋ ์์
์ ํ ๋๋ onCreateView ๋๋ onViewCreated ๋ฉ์๋ ์์์ ์ํํด์ผ ํ๋ค.
binding์ ์ ๊ทผํ๊ธฐ ์ ์๋ ์ด๊ธฐํํด์ผ ํ๋ค.
class ContactDetailFragment : Fragment() {
private lateinit var binding: FragmentContactDetailBinding
private var contactData: Contact? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
contactData = it.getParcelable(Constants.ARG_CONTACT)
}
// binding.imgDetailprofil.setImageResource(contactData!!.profileImage)
binding.tvDetailname.text = contactData?.name.toString()
binding.tvDetailMBTI.text = contactData?.mbti
binding.tvDetailPhon.text = contactData?.phoneNumber
binding.tvDetailEmail.text = contactData?.email
binding.tvDetailBirth.text = contactData?.birthDate
Log.d("๋ฐ๋ Detail ํ๋๊ทธ๋จผํธ", contactData?.phoneNumber.toString())
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.let {
contactData = it.getParcelable(Constants.ARG_CONTACT)
}
contactData?.let { data ->
// binding.imgDetailprofil.setImageURI(data.profileImage)
binding.tvDetailname.text = data.name
binding.tvDetailMBTI.text = data.mbti
binding.tvDetailPhon.text = data.phoneNumber
binding.tvDetailEmail.text = data.email
binding.tvDetailBirth.text = data.birthDate
if(contactData?.favorite == true)
binding.imgStar.setImageResource(R.drawable.icon_star_yellow)
else
binding.imgStar.setImageResource(R.drawable.icon_star_gray)
}
}
import๋ฅผ ์๋ชปํ์ ๊ฐ๋ฅ์ฑ์ด ๋๋ค.
adb shell setprop log.tag.FragmentManager DEBUG
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val bottomNav = activity?.findViewById<BottomNavigationView>(R.id.nav_view)
bottomNav?.visibility = View.GONE
}
*์ฃผ์ํ ์
destroy๋ ๋ ๋ค์ ๋ณด์ด๊ฒ ํด์ผ ํ๋ค
override fun onDestroyView() {
super.onDestroyView()
val bottomNav = activity?.findViewById<BottomNavigationView>(R.id.nav_view)
bottomNav?.visibility = View.VISIBLE
}