How to set navigation drawer in preferenceActivity

前端 未结 1 1738
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 02:22

In my app i have each activity with drawer, but when i set drawer in my Preference activity, my activity working fine, but drawer not appear.

here is my code..



        
相关标签:
1条回答
  • 2021-01-29 02:56

    In your activity's lowest hiearchical layout (content_main by default), add a FrameLayout named fragment_container. Set width and height to match_parent. Trick here is to create your fragment as this:

    getFragmentManager()
    .beginTransaction()                           
    .replace(R.id.fragment_container, new MyFragment())
    .commit();
    

    So you basically don't add a fragment to the screen, you just replace a pre-defined layout with a fragment. This prevents the issues regarding the drawer and toolbar. If not, let me know so I can investigate further.

    0 讨论(0)
提交回复
热议问题