Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Viewpager with 3 Fragment and I want by two fragments to show the actionbar and by 1 not, that's the CameraFragment!

Hi guys, when i swipe in my Viewpager the actionbar moves to the other fragment. I have 3 Fragments with in the middle the camera, i want to show and hide the actionbar at the right time. I used this viewpager at the same way Ben learned us by Ribbit. I also implemented transuclent this show the statusbar in the same color as the actionbar.

**

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(this,
            getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager
            .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

** I hope you've a solution!

Thanks in advance!

Harry James
Harry James
14,780 Points

So, when you swipe to your camera, the action bar should hide itself but it doesn't, is that the problem?

Thanks for your reply! That 's the exact problem. With normal activities it isn't hard to hide the action bar, but by using the viewpager 3 fragments are managed by one activity. So when i hide it there its hided everywhere. I would like to have two fragments with an actionbar and one without. There has to be a solution for that!

There should be a solution for that. I know for a fact you can customize action bar icons for different fragmented tabs in a single activity. Google uses this tactic in the latest update to Hangouts. I don't see why hiding it would be any different! LOVE your idea by the way. May try to impliment it myself! :D

1 Answer

Hey!

Try this...

getActionBar.hide();

Interested to see if this will work. May be a simple fix! :D

EDIT So, I've tried a few different things, and none of them have worked effectively. The proppe way to hide it would be to call

getActivity.getActionBar.hide();

but When I do so in an individual activity, it hides it for all tabs, and furthermore hides the tabs themselves.

Harry James
Harry James
14,780 Points

Ah! Nice! I think you're right here!

Haven't tested as I'm on mobile but it looks like it was the get method missing.

Hopefully! :) If it works, I may try this myself. I love the idea!