otcroz / Travel-culture

지역문화 및 축제 소개와 지역문화 활성화를 위한 서비스: 문화를 여행하다.
0 stars 0 forks source link

Navigator Bar #5

Open otcroz opened 2 years ago

otcroz commented 2 years ago

setOnNavigationItemSelectedListener deprecated 해결하기

https://velog.io/@kimbsu00/Android-8

bottomNavBar.setOnItemSelectedListener { item ->
    when(item.itemId) {
        // add your code
    }

setOnItemSelectedListener 을 사용하면 된다.

otcroz commented 2 years ago

유수연을 화나게 만든 나브바 아이콘이 보이지 않았던 이유?

BottomNavigationView에서 android:layout_width="0dp"로 설정해놓고 왜 안되지~ 이러고 있는 유수연의 멍청함


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/menu_bottom_navbar" />

image

드디어 나브바 아이콘이 보인다.. 1시간 만에

otcroz commented 2 years ago

바보같이 이것도 모르고..!!

지금까지 앱 실행할 때 홈 프래그먼트가 보이지 않았던 이유

bn.selectedItemId = R.id.navigation_home 이거 설정 안해서..

        bn.setOnItemSelectedListener{
            replaceFragment(
                when (it.itemId){
                    R.id.navigation_home -> HomeFragment()
                    R.id.navigation_map ->MapFragment()
                    R.id.navigation_list -> ListFragment()
                    else -> CourseFragment()
                }

            )
            true
        }
        bn.setOnItemSelectedListener{
            replaceFragment(
                when (it.itemId){
                    R.id.navigation_home -> HomeFragment()
                    R.id.navigation_map ->MapFragment()
                    R.id.navigation_list -> ListFragment()
                    else -> CourseFragment()
                }

            )
            true
        }
        **bn.selectedItemId = R.id.navigation_home**