Update selected state of navigation drawer after back press

后端 未结 6 1171
臣服心动
臣服心动 2021-02-19 22:56

Whats the proper way to handle the selected state of the navigation drawer after back press?

I have a navigation drawer with n entries (in a listview) like the SDK sampl

6条回答
  •  耶瑟儿~
    2021-02-20 00:01

    Here is a solution in kotlin.

    In the fragment that you want to be selected and highlighted by the drawer, you simply do:

        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
    
        val navView: NavigationView = activity!!.findViewById(R.id.nav_view)
        navView.setCheckedItem(R.id.name_of_this_fragment)
    
        ...
    }
    

提交回复
热议问题