0

Is in whats app the floating action button part of each fragment (chats, status, calls and so on) or is the fab part of the enclosing main layout that encapsulates the fragments?

Because the fab does not scroll sideways away with the fragment contents i tend to the latter case but then again i just started android programming and know nothing about layout flags or options that might cause this behaviour...

javaguy
  • 149
  • 1
  • 6
  • Have a look at this project - https://github.com/Shahar2k5/whatsappClone – HB. Aug 13 '19 at 17:21
  • thanks, that confirmed my assumption! do you happen to know where the second fab on the status page is added? – javaguy Aug 13 '19 at 18:02

1 Answers1

0

Yes, the FloatingActionButton (fab) seems to be a part of the Activity layout. The Activity likely has a ViewPager beneath the TabLayout - this is a pretty common approach to building these types of layouts. The ViewPager/TabLayout combination is set up to link the pages as you either scroll or tap the tabs to Fragments that each have their own logic and implementation associated with them. The fab sits at the Activity level so it is unaffected by the changing of pages. However the Fragments definitely modify the fab visually (you can see the icons change when you change pages) and logically so when the view is clicked it performs the correct action depending on the currently shown page.

Take a peak at this article to see a simple implementation to get your hands dirty with some of the code: https://medium.com/@Abdulkadir98/android-sliding-tabs-with-viewpager-851f9c996cb5

DMP
  • 129
  • 4
  • Is there a difference between Tablayout and PagerTabStrip? Do you know whether its either the one or the other? Also yes noticed too that the button changes, must be a sort of tabchangelistener that changes its icon and actionsettings... – javaguy Aug 13 '19 at 17:47
  • @javaguy take a peak at this post to answer your question about the PagerTabStrip: https://stackoverflow.com/questions/35668443/difference-between-pagertabstrip-and-tablayout. I personally have not used it, but I know the UI element after reading that post. In regards to the dynamic fab updates, there are a few ways you could accomplish this and the one you mentioned is a possibility. One could also open the fab up to the Fragments and let them control the view instead of the Activity managing its state! – DMP Aug 13 '19 at 17:55