Animated toolbar with fragments

I have a MainActivity that implements a navigation box using the following xml:

<android.support.v4.widget.DrawerLayout xmlns:android ="http://schemas.android.com/apk/res/android" android:id ="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/container_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <include android:id="@+id/toolbar" layout="@layout/toolbar" /> </LinearLayout> <FrameLayout android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#FFFFFF"/> </LinearLayout> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity ="start" > <ListView android:id="@+id/drawerList" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="5dp" android:divider="@color/material_blue_grey_800" android:dividerHeight="1dp" android:background="#FFFFFF" /> </RelativeLayout> </android.support.v4.widget.DrawerLayout> 

Now I have 3 elements in my list, and when I click on any of them, my code replaces Framelayout with that private fragment, as shown below:

 Fragment f1 = new Fragment() FragmentTransaction ft = getSupportFragmentManager().beginTransaction() ft.setCustomAnimations(R.anim.slide_in,R.anim.hyper_out,R.anim.hyper_in,R.anim.slide_out) ft.replace(R.id.content, f1).addToBackStack(null).commit(); 

The code above is great for replacing a fragment with custom animation. However, my question is how to animate the toolbar along with the fragment during fragment transactions.

All fragments have their respective names on the toolbar, which are changed in the onActivityCreated () method for each fragment class with the following code:

 ((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("Title"); 

Should I apply animations to my layouts to hide the toolbar?

+6
source share

Source: https://habr.com/ru/post/989051/


All Articles