Android:折叠工具栏时阻止选项菜单
我有一个正在折叠的工具栏,其中有一个片段中的选项菜单。当我折叠工具栏时,菜单会移动到状态栏上方。所以,在崩溃之后,我看不到 菜单选项。我在截图中显示: 下面是我的.xml代码:Android:折叠工具栏时阻止选项菜单,android,toolbar,Android,Toolbar,我有一个正在折叠的工具栏,其中有一个片段中的选项菜单。当我折叠工具栏时,菜单会移动到状态栏上方。所以,在崩溃之后,我看不到 菜单选项。我在截图中显示: 下面是我的.xml代码: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-au
<android.support.design.widget.CoordinatorLayout
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="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/abl_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/ctl_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
<ImageView
android:id="@+id/iv_avatar"
android:layout_width="match_parent"
android:layout_height="220dp"
android:src="@drawable/ic_main_logo"
android:scaleType="centerInside"
android:background="@drawable/shape_profile_avatar_background"
app:layout_collapseMode="parallax"/>
<include layout="@layout/component_transparent_toolbar"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_results"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:elevation="4dp"
app:elevation="4dp"
app:srcCompat="@drawable/vector_photo_camera_black_24dp"
app:layout_anchor="@id/abl_toolbar"
app:layout_anchorGravity="bottom|right|end"/>
<include layout="@layout/component_profile_avatar_bottom_sheet" />
知道为什么会这样吗
编辑/解决:
我解决了我的问题。错误是在工具栏属性中,我忘记了app:layout\u collapseMode=“pin”。在
layout.xml
活动的布局文件中设置工具栏的设计代码&
在活动中设置工具栏,如下所示
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//在活动文件中添加这行代码。我在状态栏上看不到任何内容。你们到底是什么意思?我的选项菜单,在第一个屏幕截图中,在我折叠工具栏时消失了-第二个屏幕截图我不能在活动xml文件中移动工具栏。如您所见,屏幕具有底部导航视图。活动使用完全不同的工具栏和功能实现两个片段。所以我只能将工具栏膨胀成碎片
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
setSupportActionBar(toolbar);