2 回答

TA貢獻1864條經驗 獲得超2個贊
你activity_student_home不包括你的 DrawerLayout
這個不見了
<include
layout="@layout/app_bar_student_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />

TA貢獻1776條經驗 獲得超12個贊
做你想做的事情的正確方法是(如果我理解你的要求正確的話)使用片段
在你的 app_bar_student_home.xml 里面替換
<include layout="@layout/content_student_home" />
像這樣的東西
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent"/>
然后創建您希望顯示其內容的片段(例如 FragmentA、FragmentB)并將它們的 contentview 設置為您希望顯示的不同布局
當您希望更改活動的內容時,您可以執行以下操作
getSupportFragmentManager().beginTransaction().replace(R.id.content, new FragmentA()).commit();
遠不止這些,
例如,當您希望將片段中的點擊事件發送到您的活動時,您必須使用 getActivity() 并將其轉換為 MainActivity 的類或使用接口(首選)
您可以查看本教程,該教程應該對您有所幫助
http://www.androiddocs.com/training/basics/fragments/index.html
添加回答
舉報