我已經在空白活動(Android Studio)上創建了整個項目。我想添加一個導航抽屜而不妨礙我以前的代碼。是否有一種方法可以將導航抽屜添加到空白活動中,如果是的話請引導。添加導航抽屜以空白活動
0
A
回答
1
第1步:將導航視圖包含到您的xml文件中,這將通過創建時的yor活動進行膨脹。
<?xml version="1.0" encoding="utf-8"?>
<include
layout="@layout/app_bar_main"
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_main"
app:menu="@menu/activity_main_drawer" />
第二步:初始化觀點
private NavigationView navigationView;
private DrawerLayout drawer;
第三步:發送事件的抽屜關閉和打開
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) {
@Override
public void onDrawerClosed(View drawerView) {
// Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
// Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank
super.onDrawerOpened(drawerView);
}
};
//Setting the actionbarToggle to drawer layout
drawer.setDrawerListener(actionBarDrawerToggle);
//calling sync state is necessary or else your hamburger icon wont show up
actionBarDrawerToggle.syncState();
}
希望這有助於設置導航抽屜。
+0
它幫助,謝謝,欣賞它:) – Anonymous
0
<android.support.v4.widget.DrawerLayout android:background="@drawable/icon" android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/drawerLayout" xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/mainContent"> </FrameLayout>
<ListView android:background="#ff8800" android:layout_height="match_parent" android:layout_width="240dp" android:id="@+id/lvLeft" android:dividerHeight="0dp" android:divider="@android:color/holo_blue_bright" android:choiceMode="singleChoice" android:layout_gravity="left"> </ListView>
<ListView android:background="#0077ff" android:layout_height="match_parent" android:layout_width="240dp" android:id="@+id/lvRight" android:dividerHeight="0dp" android:divider="@android:color/transparent" android:choiceMode="singleChoice" android:layout_gravity="right"> </ListView>
</android.support.v4.widget.DrawerLayout>
+0
除了格式化的代碼外,您還應該給解答添加解釋 –
相關問題
- 1. 導航抽屜活動
- 2. 添加導航抽屜AppCompatActivity
- 3. 動態添加MDL導航抽屜
- 4. 將滑動視圖添加到導航抽屜活動
- 5. 如何在所有活動中添加導航抽屜
- 6. Android |將導航抽屜添加到默認地圖活動
- 7. 如何使用ArrayAdapter添加項目到導航抽屜活動
- 8. 如何在導航抽屜活動中添加Google地圖?
- 9. 添加(開/關)按鈕活動(開/關)導航抽屜
- 10. 導航抽屜中的地圖活動
- 11. 導航抽屜意向活動Android Studio
- 12. 導航抽屜RecyclerView Items點擊活動
- 13. NoSuchFieldError在抽屜式導航活動
- 14. 導航抽屜中的打開活動
- 15. 帶TabLayout的導航抽屜活動,ViewPager
- 16. 導航抽屜活動中的錯誤
- 17. 擴展導航抽屜活動
- 18. 擴展導航抽屜活動
- 19. 所有活動中的導航抽屜
- 20. 所有活動的導航抽屜
- 21. 導航抽屜活動Android Studio
- 22. 項目導航抽屜打開活動
- 23. onitemclicklistener在抽屜活動不工作的導航抽屜
- 24. 如何將選項卡式活動添加到導航抽屜活動中?
- 25. 添加按鈕,導航抽屜片段
- 26. 添加項目到導航抽屜
- 27. 嚮導航抽屜添加switch語句
- 28. 在導航中添加圖標抽屜
- 29. 將標題添加到導航抽屜
- 30. 將圖標添加到導航抽屜
檢查此鏈接https://developer.android.com/training/implementing-navigation/nav-drawer.html – Swr7der
@ Swr7der謝謝你,有沒有可能,如果你可以發送源代碼,如果完全好你不能 – Anonymous
這是,但你應該嘗試自己學習和編碼。這對你有好處。如果在此之後,你面臨問題,然後在這裏發帖。有同行可以幫助你。快樂編碼:) – Swr7der