How to select the first item in a navigation drawer and open a fragment on application start

前端 未结 8 509
鱼传尺愫
鱼传尺愫 2021-02-04 05:32

I have created MainActivity with NavigationView. When Activity is opened I want to automatically select the first item in the navigation d

8条回答
  •  独厮守ぢ
    2021-02-04 06:09

    In onCreate(), following code will load the first item's fragment upon first start:

    if (savedInstanceState == null) {
        navigationView.getMenu().performIdentifierAction(R.id.posts, 0);
    }
    

    Thanks to calvinfly for this comment.

提交回复
热议问题