7

I've been trying out implementing navigation in android through navigation drawers and swipe views with tabs. I've followed Google's developer tutorials (here and here) and for both situations I could never get my code to work unless I changed Activity or FragmentActivity to AppCompatActivity and applied other changes in the action bars code, for instance change getActionBar to getSupportActionBar so I don't get NPE.

Now the questions:

1- Why do I need to make these changes when I'm following official tutorials that should work the way they are?

2 - Is AppCompatActivity correct to use in these cases or is there a better way to do the same thing?

3 - Are these situations related to the min sdk and target sdk I chose? My min sdk is 14 and my target sdk is 22. Should I try to lower the target sdk?

4 - Are these situations related to the style/theme of my application? It's android:theme="@style/AppTheme" > .

Some insight on this subject is appreciated so thank you in advance.

Edit: Another thing I noticed is that I always need to import android.support.v7.app.ActionBar instead of android.app.ActionBar so I don't get NPE, even though my min sdk is higher than API 11.

Edit2: I noticed some contradiction in the developers' guides. Because I want to use ActionBar, I need to get my imports right. Following this link, it's recommended that I include v7 appcompat libraries, but following this one I need to import android.app.ActionBar because my min sdk is higher than 11. Like I said before, using android.app.ActionBar produces NPE, so what should I do?

user3641702
  • 393
  • 1
  • 5
  • 18
  • 1
    You may want to inspect sources of this sample project: https://github.com/chrisbanes/cheesesquare – Marcin Orlowski Jun 29 '15 at 17:28
  • Although the sources have code that I can check, they still don't answer my questions. Why do I have to use AppCompatActivity instead of Activity or FragmentActivity like in the Google Developer tutorials? – user3641702 Jun 29 '15 at 21:10
  • 1
    You are implementing it the old way. Look at @MarcinOrlowski 's link. 1. Official tutorials are outdated. 2. Yes. 3. No. 4. Use the `Toolbar`. – Jared Burrows Jun 30 '15 at 14:23

0 Answers0