我已經在空白活動(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. 動態添加MDL導航抽屜
- 2. 如何在導航抽屜活動中添加Google地圖?
- 3. Android |將導航抽屜添加到默認地圖活動
- 4. 導航抽屜意向活動Android Studio
- 5. 帶TabLayout的導航抽屜活動,ViewPager
- 6. 項目導航抽屜打開活動
- 7. 所有活動的導航抽屜
- 8. NoSuchFieldError在抽屜式導航活動
- 9. 導航抽屜活動Android Studio
- 10. 如何將選項卡式活動添加到導航抽屜活動中?
- 11. 在片段上添加導航抽屜
- 12. 添加按鈕,導航抽屜片段
- 13. 如何添加向右滑動以打開導航抽屜
- 14. 添加導航抽屜以滑動視圖
- 15. Android導航抽屜?
- 16. Android導航抽屜激活帶按鈕
- 17. 按下返回按鈕時的導航抽屜活動爲空活動
- 18. 如何在使用導航抽屜的片段時在底部導航欄上添加導航抽屜?
- 19. 導航抽屜與導航抽屜片段
- 20. 是否可以嚮導航抽屜按鈕添加聲音?
- 21. 我可以在導航抽屜佈局添加圖像頭
- 22. 導航抽屜空指針異常
- 23. 在導航抽屜中添加Google地圖活動時出錯(材質設計)
- 24. 將導航抽屜活動模板添加到現有項目中
- 25. 添加圖標在導航抽屜手動
- 26. 如何添加項目動態點擊導航抽屜
- 27. 在導航抽屜中添加項目動態
- 28. ReactNative抽屜:空白屏幕
- 29. 新的活動不啓動時,點擊導航抽屜項目
- 30. 如何從底部導航抽屜啓動活動?
檢查此鏈接https://developer.android.com/training/implementing-navigation/nav-drawer.html – Swr7der
@ Swr7der謝謝你,有沒有可能,如果你可以發送源代碼,如果完全好你不能 – Anonymous
這是,但你應該嘗試自己學習和編碼。這對你有好處。如果在此之後,你面臨問題,然後在這裏發帖。有同行可以幫助你。快樂編碼:) – Swr7der