Facebook iconInstagram like Bottom tab Fragment Transaction Android
Blogs/Technology

Instagram-like Bottom tab Fragment Transaction Android

May 11, 20172 Min Read
by Murtuza Kutub
Instagram-like Bottom tab Fragment Transaction Android Hero
Have you ever faced issues with fragment?

The Answer from all the techies would be “Yes”, because dealing with Fragments are not direct, simple and easy to implement. I know handling backstacks with add and replace are like “The Ghost and the darkness”.

What inspired me to write this post?

Partner with Us for Success

Experience seamless collaboration and exceptional results.

Partner with Us for Success

Experience seamless collaboration and exceptional results.

The reason is “Instagram”. I love to play with Insta app since it is easy, robust and less screen navigation, which in turn collectively bottom tab navigation took the peek place in the Android community.

Is that hard to implement sticky Bottom tabs with Fragments transactions in all the screens?

Yes, before this post peeped in :)

Ok! let's do some technical stuff. In this article, we’re gonna implement Bottom tabs with Fragments and nested Fragment transactions. Confused! Following Gif explains in a better way.

Yeah! Here if you see the above Gif, there are five tabs like Home, Search, Share, News and Profile. Selecting each tab options, respective Fragments are pushed. That’s obvious isn’t? Cool! If you notice keenly, I have assigned “CLICK ME” button for Home and News Fragments to showcase the behaviour of Nested Fragments Transactions inside same Fragments without losing its state. Let’s do it in a linear way.

Fragments
  1. Tap on “CLICK ME” button.
  2. Can you see that Toolbar text has changed from “Home” to “Sub Home 1” and so on till “Sub Home 4” by clicking it four times? Yes! It does!, all these Sub Home 1 ….. Sub Home 4 are nested fragments inside Home (Main Fragment) . Ideally, new fragments are pushed and replaced with one after the other with successive clicks. Yup! Bottom bars are always fixed too.
  3. Now navigate to another tab, come back again and check the behaviour in “Home” tab. The state is maintained with the same screen where you left (Sub Home 4, 4th fragment) :)
  4. Finally, click back button and experience the behaviour that previous fragments are popped in automatically without losing the previous states. Yeah! This works even with back soft key.
Home Fragments

Why TabLayout instead of Design support BottomNavigationView?

I have plenty of reasons for the same as below:

  1. It’s not flexible.
  2. Random behaviour if there are less tab items.
  3. Customising text sizes and icon sizes are like a nightmare (Just try adding small sized icon for one tab and big sized icon for the other.
Author-Murtuza Kutub
Murtuza Kutub

A product development and growth expert, helping founders and startups build and grow their products at lightning speed with a track record of success. Apart from work, I love to network & Travel.

Phone

Next for you

How to Integrate Google Maps into Your Flutter App Cover

Technology

Nov 20, 20244 min read

How to Integrate Google Maps into Your Flutter App

In our smartphone-driven world, location services are transforming the app landscape. The global location-based services market is projected to hit a staggering reach USD 129.71 billion by 2032, exhibiting a CAGR of 19.5% during the forecast period (2024-2032) This explosion stems from our smartphone addiction and hunger for personalized experiences. It's only natural that developers are rushing to integrate Google Maps into their apps, aiming to deliver an engaging, user-friendly mapping experi

How To Implement Dark Mode in Your Flutter App Cover

Technology

Oct 24, 20244 min read

How To Implement Dark Mode in Your Flutter App

In today's app-driven world, dark mode has become a must-have feature. A 2021 Android Authority survey found that an overwhelming 81.9% of users prefer dark mode in their apps. This trend highlights the need for Flutter developers to incorporate this feature to enhance user satisfaction and stay competitive. Understanding Theming in Flutter Flutter theming is the foundation for implementing dark mode. It provides a systematic way to manage your app's visual elements, ensuring consistency and

How to Implement Drag-and-Drop in Flutter? Cover

Technology

Oct 22, 20245 min read

How to Implement Drag-and-Drop in Flutter?

Have you ever marvelled at how smoothly you can rearrange apps on your smartphone's home screen? That's the magic of drag-and-drop at work. As a Flutter developer, you have the power to bring this same intuitive interaction to your apps. Let's dive into the world of Flutter drag and drop and discover how you can create interfaces that users will love to touch, drag, and interact with. Why Drag-and-Drop Matters in Modern Apps Picture this: you're scrolling through a to-do list app, and instea