Android Toolbar后退按钮未显示在详细信息片段中

时间:2019-06-22 09:57:30

标签: android android-layout android-actionbar android-toolbar android-collapsingtoolbarlayout

我有以下情况:
我有一个活动和两个片段,一个包含/显示项目(电影项目)列表,下一个是详细信息片段。在主要活动中,我有一个操作栏(可折叠),显示片段的标题。
现在,如果我转到详细信息片段,操作栏会折叠,但不会显示操作栏后退按钮。它在崩溃时是有道理的,但是,我想知道有什么选择可以使其再次显示。

活动xml:

# Create your models here.
from immob.models import structure
from django.db import models
from django.contrib.auth.models import User

class utilisateur(models.Model):
    user=models.OneToOneField('auth.User', on_delete=models.CASCADE)
    structure=models.ForeignKey(structure,on_delete=models.CASCADE)


应用栏布局,app_bar_main.xml:

 <androidx.drawerlayout.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">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <include
            layout="@layout/app_bar_main"

            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <fragment
            android:id="@+id/nav_container_id"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:navGraph="@navigation/navigation_graph" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_left_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>


在细节片段中,以下部分用于显示封面照片:

<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:theme="@style/AppTheme.AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</com.google.android.material.appbar.AppBarLayout>


我附上了四张图片以防不清楚:
工作案例
电影列表:

Movie list with action bar shown.

细节片段:
Detailss view with back button shown.


不可行。
电影列表:

Movie List action bar folded


详细信息片段:
Details view not working

编辑
 经过一番调查,我得出了一个好的解决方案,但不是最好的解决方案:
每次我进入详细信息屏幕时,都会将扩展标志设置为false。它可以工作,但是当按下时它不会显示汉堡动画->从后退到汉堡按钮的过渡。感觉就像一个普通的后退按钮。

任何人都知道如何将这些东西绑在一起,例如从主片段到细节片段的Appbar吗?我找到了一些相关的东西,例如每个片段的工具栏都不同,等等。我尝试过,但是问题是将它与抽屉菜单连接起来并不容易。

0 个答案:

没有答案