Application with Navigation Drawer, Tabs and Fragments

Asked

Viewed 197 times

0

I made an application with Navigation Drawer making use of the AS wizard, on the first screen "Mainactivity" implemented a layout with Tabslayout and Viewpager and everything is working perfectly, this app has other activities and these do not have access to Drawer, only that the application requester asked me this, I thought I would go copying in all other activities to get to this implementation more even with few activities 6 this would give a certain work well "repetitive", so I thought to use Fragments.

With Fragments my work would be reduced since the "core" of the screen would be updated and this would reduce my work of having either leave by inserting Drawer in all other more.... , I’m finding it difficult to use Fragments and refactoring my app which came to me so the question is a good practice to have an app with these features? the IDE itself in its assistants or gives option to one or the other, I searched for examples with Drawer and Tabs or for any post that addresses the subject, find Drawer and Fragments further within this with Tabs not.

I even managed in this my first activity put in a Fragment only I have found problems with Tabs that did not stay together with Toobar, if I rotate the device the content of Tabs disappears, so after I select one or the other that the same appears, so I’m even afraid to go into other activities turning them into Fragments.

Is it a good practice an application with these elements?

  • Interested in good practice?! Check this out: https://github.com/futurice/android-best-practices

  • What to be 'AE’s assistant'?

  • 1

    Hello Ack Lay good afternoon, dear sorry I made the fix is AS - Android Studio

1 answer

-2

Hello, I use tabs with Fragments in a good, the question of rotation is why the android destroys your Activity and recreates in the new orientation, this can be bypassed, I will leave some links below that will help:

http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/ https://android.jlelse.eu/handling-orientation-changes-in-android-7072958c442a

On the issue of guidance, a simple way to resolve is to inform android that you do not want your Activity to be recreated after the rotation. Just put the code below on Androidmanifest:

<activity
android:name="meu.pacote.MinhaActivity"
android:configChanges="orientation|screenSize|keyboardHidden"/>
  • 1

    This link may be a good suggestion, but your reply will not be valid if one day the link crashes. In addition, it is important for the community to have content right here on the site. It would be better to include more details in your response. A summary of the content of the link would be helpful enough! Learn more about it in this item of our Community FAQ: We want answers that contain only links?

  • Hello Fernando I agree that tabs and Fragments is quiet, but add to that the Navigaton Drawer and keep it for any activity or new fragment called Drawer this is the case I have to solve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.