Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Using Fragments for Tabs Understanding the Rest of the Pieces

Erik van de Ven
Erik van de Ven
2,353 Points

setnavigationmode is deprecated

Don't know what's with you guys, but my Android Studio is telling me that setNavigationMode is deprecated. So I wasn't able to view the tabs in the actionbar.

4 Answers

Erik van de Ven
Erik van de Ven
2,353 Points

I pretty much figured out a solution. After watching this video (https://www.youtube.com/watch?v=tRg_eDfQ8fk) and reading the comments I was able to create two tabs. Still not the same as Ben created, but they work.

First make sure the activity_main.xml has a LinearLayout with the ViewPager INSIDE of it (and a SlidingTabLayout above it), like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_height="wrap_content" />

        tools:context=".MainActivity" />

Then use the sample code from the android developer site to create 2 java classes: "SlidingTabLayout.java" (http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html) and "SlidingTabStrip.java" (http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabStrip.html)

don't forget to change the sample package names (=package com.example.android.common.view;) to your package names, for example com.my_company.ribbit;

And finally create another variable in MainActivity.java below SectionsPagerAdapter:

SectionsPagerAdapter mSectionsPagerAdapter;
SlidingTabLayout mSlidingTabLayout; //this one

And define the mSlidingTabLayout below the ViewPager inside MainActivity.java:

mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);

That's pretty much it.

it compiles well as you said. But the action bar does't turn out.

Hi all, one small hints - if anyone is not very familiarize yet with re writing the code you can still use the old library which was used by Ben and all function will be working (as for old code). As far I am concern it is not a recommended method however if someone is not able yet to write a new code for tabs please just use function import from Eclipse project and import project which is available in download section under video (this function is visible on the first wizard window in Android studio). Or go to file and then select Import Project.

The library which used for compiling the project from video is [com.android.support:support-v4:19.1.0].

Cheers, Hubert

If you want the new implementation, I've worked it all out here:


Please let me know if anything isn't working or is confusing, I've pretty fast with responses and updates.

Hi Nicolas great work! :) Thank you.