且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在首选项中设置导航抽屉

更新时间:2023-11-26 14:06:28

在活动的最低层级布局(默认情况下为content_main)中,添加一个名为fragment_container的FrameLayout.将宽度和高度设置为match_parent.这里的技巧是按照以下步骤创建您的片段:

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.