Animation for action bar show action
I am using android 4.2 with latest appCompat. I have implemented showing and hiding the action bar using these methods:
final ActionBar actionBar = getSupportActionBar();
actionBar.hide();
actionBar.show();
When the action bar is hidden, it does so when the flowing animation gradually accelerates. However, when I show it, it appears on the screen almost instantly with almost no smooth animation sliding down. Is there a way to tweak it so that it displays smoothly as it does by hiding it?
+3
source to share
2 answers
Set in your layout android:animateLayoutChanges="true"
toAppBarLayout
<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 to hide or show the toolbar (ActionBar)
if (getSupportActionBar() != null) {
if (getSupportActionBar().isShowing()) {
getSupportActionBar().hide();
} else {
getSupportActionBar().show();
}
}
+1
source to share