【问题标题】:Animation for action bar show action动作栏显示动作的动画
【发布时间】:2015-05-08 06:14:51
【问题描述】:

我正在使用带有最新版本 appCompat 的 android 4.2。我已经使用这些方法实现了显示和隐藏我的操作栏:

final ActionBar actionBar = getSupportActionBar();
actionBar.hide();
actionBar.show();

当动作条被隐藏时,它会随着平滑的动画逐渐向上滑动。然而,当我展示它时,它几乎立即出现在屏幕上,几乎没有平滑的动画向下滑动。有什么方法可以将其配置为在隐藏时平滑显示?

【问题讨论】:

  • 你启用了这个属性 setShowHideAnimationEnabled() 吗?
  • 好像是这个,非常感谢!让它成为一个答案,以便我可以接受它。另外请澄清一下,ShowHideAnimation 默认是禁用的吗?

标签: android android-actionbar


【解决方案1】:

尝试启用默认未启用的 ActionBar 隐藏/显示动画,因此请使用以下代码启用隐藏/显示动画:

actionBar.setShowHideAnimationEnabled(boolean enabled);

【讨论】:

【解决方案2】:

在你的布局中设置android:animateLayoutChanges="true"AppBarLayout

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    android:animateLayoutChanges="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"

        />

</android.support.design.widget.AppBarLayout>

并切换隐藏或显示工具栏(ActionBar)

if (getSupportActionBar() != null) {

    if (getSupportActionBar().isShowing()) {
        getSupportActionBar().hide();
    } else {
        getSupportActionBar().show();
    }
}

【讨论】:

  • 到目前为止,这是最干净的答案。
猜你喜欢
  • 2018-07-26
  • 1970-01-01
  • 2015-08-07
  • 2022-06-13
  • 2022-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多