问题
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