Animation for action bar show action

為{幸葍}努か 提交于 2021-02-19 05:09:22

问题


I'm using android 4.2 with appCompat of the latest version. I've implemented showing and hiding my action bar with these methods:

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

When action bar is being hide, it does so with smooth animation gradually sliding up. However, when I show it it appears on the screen almost instantly, almost without smooth animation sliding down. Is there any way I can configure it to show smoothly as it happens with hiding it?


回答1:


Try to enable ActionBar hide/shown animation which is by deafult not enable so enable hide/shown animation using below code :

actionBar.setShowHideAnimationEnabled(boolean enabled);



回答2:


Set in you layout android:animateLayoutChanges="true" in 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>

And Toggle for hide or show toolbar (ActionBar)

if (getSupportActionBar() != null) {

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


来源:https://stackoverflow.com/questions/30116936/animation-for-action-bar-show-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!