1

I have an activity(let's call it Home Activity) with bottom navigation view where I replace all of my fragments. In Home Activity I have loaded a fragment which has a search icon. That search icon redirects to an activity that is Search Activity.

When I click any of the search result I go to my Home Activity and replace the previous fragment to show my recent search result click implementation.

In this case, the complexity is - when I'm trying to replace the previous fragment - it's visible to the user. And as I have a transition animation - I can see the previous fragment is exiting and the latest fragment is entering.

This is not at all a good experience for the user. How may I improve the functionality so that previous fragment is not visible to the user?

Farwa
  • 6,156
  • 8
  • 31
  • 46

2 Answers2

1

Try out this code section. Create animation as you need.

public static void callFragment(Fragment fragment, Context context, String TAG) {
    FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    if (fragment.isAdded()) {
        fragmentTransaction.show(fragment);
    } else {
        //   fragmentTransaction.setCustomAnimations(R.anim.fade_in, R.anim.face_out);
        fragmentTransaction.setCustomAnimations(R.anim.fragment_slide_top_enter, R.anim.fragment_slide_top_exit, R.anim.fragment_slide_bottom_enter, R.anim.fragment_slide_bottom_exit);
        fragmentTransaction.replace(R.id.content_frame, fragment);
        fragmentTransaction.addToBackStack(TAG);
    }
    fragmentTransaction.commit();
}

And also provide background to your fragment layout files.

Prasad PH
  • 105
  • 7
0

Fragments are by default transparent. So you need to give background to your search result fragment. To give backgroind set background on root of your layout.

Sunny
  • 14,522
  • 15
  • 84
  • 129