【发布时间】:2018-06-26 21:59:10
【问题描述】:
场景:
当其中一个toolbars 消失时,第二个toolbar 将适应第一个toolbar 的scrollFlag,而不是它自己的scrollFlag!
注意:
只有当toolbars 之一是gone 时才会发生奇怪的行为,
如果它们都是visible,则scrollFlag 属性被正确设置为每个工具栏。
示例 1:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.Toolbar
android:id="@+id/appbar_edit_toolbar"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/accent"
app:contentInsetStart="@dimen/content_inset"
app:navigationIcon="@drawable/ic_clear"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@android:color/white"
tools:ignore="UnusedAttribute" />
<android.support.v7.widget.Toolbar
android:id="@+id/appbar_normal_toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:contentInsetStart="@dimen/content_inset"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name"
tools:ignore="UnusedAttribute" />
</android.support.design.widget.AppBarLayout>
在这种情况下运行应用程序时,当显示toolbars 之一时,它的scrollFlag 行为与appbar_edit_toolbar 相同(即:滚动时始终显示的默认行为),而不是@显示 987654334@,其 scrollFlag 行为应为 scroll|enterAlways,如 xml 中所示。
示例 2:
<android.support.v7.widget.Toolbar
android:id="@+id/appbar_normal_toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:contentInsetStart="@dimen/content_inset"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name"
tools:ignore="UnusedAttribute" />
<android.support.v7.widget.Toolbar
android:id="@+id/appbar_edit_toolbar"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/accent"
app:contentInsetStart="@dimen/content_inset"
app:navigationIcon="@drawable/ic_clear"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@android:color/white"
tools:ignore="UnusedAttribute" />
</android.support.design.widget.AppBarLayout>
在这种情况下运行应用程序时,当显示toolbars 之一时,它的scrollFlag 行为与appbar_normal_toolbar 中的一样(即:scroll|enterAlways),而不是在显示appbar_edit_toolbar 时,它的scrollFlag 行为应该是默认的(即始终显示)。
我尝试动态设置scrollFlags 属性,使AppBarLayout 无效,但这不起作用。
我很确定这种行为的发生是由于 Android 库中的一个错误,因为他们不希望我消失其中一个工具栏。
你们怎么看?有什么其他方法可以让我的 Activity 有 2 个不同的工具栏,每次只能看到其中一个?
【问题讨论】:
-
为什么在同一页面中需要两个工具栏。 !!
-
@ragu-swaminatahan 我的活动处理激活第一个工具栏或第二个工具栏的“模式”标志。他们每个人都有不同的外观和菜单来膨胀。
-
您可以使用单个工具栏并在代码中动态处理它们,这更简单
-
@idish 你的代码有什么问题。对我来说,滚动标志的正确行为
-
@RaguSwaminathan 使用单个工具栏并不是非常“设计”的解决方案,正如我所说,每个工具栏都代表我的活动的不同状态,并且它们具有不同的外观和菜单项。跨度>
标签: android scroll visibility android-toolbar android-appbarlayout