【发布时间】:2016-03-06 15:17:48
【问题描述】:
我试过了。我不成功。我正在写我的步骤。如果有人可以帮助我。
- 使用 Android Studio 创建新项目并选择“导航抽屉活动”
-
我将 FrameLayout 放在主要活动中,如下所示
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> <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" /> </android.support.v4.widget.DrawerLayout> -
我使用 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); } } -
我做了片段管理器,如下,
public class FragmentManager extends Fragment { } -
调用 **public boolean onNavigationItemSelected(MenuItem item) **
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();
我学了一点,但没能成功。它不是在召唤。
如果我通过 Intent 调用它,它会删除 NAVIGATION ;(
如何正确使用侧边菜单。
谢谢。
【问题讨论】:
-
你可以在这里查看我的答案stackoverflow.com/a/47590216/5381331
标签: android android-fragments navigation-drawer