我試過了。我沒有成功。我正在寫我的步驟。如果任何人都可以幫助我。如何在導航抽屜中使用片段?
- 創建使用Android Studio的新建項目,然後選擇 「抽屜式導航活動」
我把FrameLayout裏的主要活動中,如下
<include layout="@layout/app_bar_vshome" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_vshome" app:menu="@menu/activity_vshome_drawer" /> <!-- Framelayout to display Fragments --> <FrameLayout android:id="@+id/frame_container" android:layout_width="match_parent" android:layout_height="match_parent" />
我做新類,如下使用v4.app.Fragment
public class VSAllTopics extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_all_topics, container, false); } }
我做片段Mananger,如下,
public class FragmentManager extends Fragment { }
調用**公共布爾onNavigationItemSelected(菜單項項)**
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction();
if (id == R.id.nav_camera) { ft.replace(R.id.frame_container, new VSAllTopics(), "VS_ALL").commit();
我研究了一點,但我沒能成功。它不是在呼喚。
如果我把它通過的意圖,它消除了導航;(
如何我可以使用側面菜單在適當的滿耳
THANKS
你可以在這裏查看我的答案https://stackoverflow.com/a/47590216/5381331 –