В настоящее время я перепроектирую свое приложение, чтобы включить навигационный ящик для навигации по приложению. В настоящее время каждый экран - это активность и способ, которым я создал домашний экран, состоит в том, что он содержит панель инструментов и другой файл xml.Реализация навигационного ящика в действии с фрагментами
<?xml version="1.0" encoding="utf-8"?>
<Toolbar
android:layout_width="match_parent"
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay">
<ImageView
android:layout_width="@dimen/_30sdp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_95sdp"
android:src="@drawable/logo"
android:id="@+id/logo"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sync_green"
android:id="@+id/sync_button"
android:layout_marginStart="@dimen/_75sdp"/>
</Toolbar>
<include layout="@layout/activity_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/run"
/>
Теперь, я сделал еще один файл XML для панели навигации:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<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:menu="@menu/activity_main_drawer" />
Мой dilemna является то, что, так как моя панель инструментов в home.xml фрагмент, когда я переключаю фрагменты, я потеряю панель инструментов. Я хочу сохранить панель инструментов для всех видов в навигационном ящике.
Кроме того, в моем java-коде setActionBar (панель инструментов) выдает сообщение об ошибке, не могу разрешить метод setActionBar.
Итак, я должен поместить свою панель инструментов в базовую операцию? Как насчет XML? Могу ли я поставить его вместе с drawerlayout? И я не могу использовать supportActionBar, я не использую библиотеку поддержки для этой панели инструментов. –
проверьте выше код и расположение –