-1

I'm currently writing an app in the Android Studio. Only my second app I'm writing natively. As I want to support API 16 until API 22 and want to have material design interfaces I've found out I need AppCompact to support Material Design < API 21 (or 20.. forgot) and above that I can just make a new styles.xml for API 21 and up.

However a few problems came up. First problem: it crashed on this

public class Example extends ActionBarActivity {
// changed it to: 
public class Example extends Activity {

Now on my Nexus 6 everything is working fine. However my text is invisible for some reason since I made a new styles.xml with primary, primary dark & accent colors.

Secondly, since I had to remove the ActionBarActivity in the .java file, the actionbar is gone on devices below API 21. How can I re-add it? Or isn't that possible? Having a hard time finding out how it works since information on the internet is mostly outdated for implementing the latest stuff.

Many thanks in advance

Edric
  • 24,639
  • 13
  • 81
  • 91
Jesse
  • 544
  • 5
  • 24
  • 1
    show crash stacktrace – Marcin Orlowski Aug 12 '15 at 19:17
  • First problem is solved by changing to Activity. However it results into another problem. I was only hoping on some explanation on the behaviour from the first eror; It's well known on the internet but doesn't seem to have any valid explanation. – Jesse Aug 12 '15 at 19:23

1 Answers1

1

You should actually extend your activity to AppCompatActivity which is latest and recommended by google. ActionBarActivity is deprecated.

And you should use toolbar instead of actionbar , again a material design pattern. for how to use it you can find it here: toolbar tutorial

If you are using the latest android design support library , you may use AppBarLayout instead of default action bar. A great guide to use the new design support library can be found here

Avinash
  • 106
  • 7
  • Thanks! I'll dig into it. So in order to support API 16 to 22 I have to use AppCompat? Even for API 21 & 22 because they support it without the AppCompact ... It's so confusing. – Jesse Aug 12 '15 at 19:38
  • 1
    AppCompatActivity is compatible with min API 7, so no worries of compatibility.here you can find more details of the compatibility: [link](http://stackoverflow.com/questions/29797172/whats-the-enhancement-of-appcompatactivity-over-actionbaractivity) and an example of AppCompatActivity usage [Link](https://androidresearch.wordpress.com/2015/04/24/example-usage-of-appcompatactivity-in-android/) – Avinash Aug 12 '15 at 19:48
  • Thanks for the resources and comments. I'll dig into everything. However is there any resource online that provides information about when things get deprecated and recommended practices by Google? – Jesse Aug 12 '15 at 19:54
  • 1
    Keep your android studio and android sdk up-to-date. Every deprecated method/class will be marked. Just **ctrl+q** over it to read the documentation. – Avinash Aug 12 '15 at 19:59
  • maybe one more question though. So I figured out how to do it now because of your help. Only question I'm left with is. If I would develop API 21 & 22 only. Would I have to program it differently? So ditch the Compat libs or are they ALWAYS used even though you are using stuff from the API that supports it natively – Jesse Aug 12 '15 at 20:09
  • 1
    _best way to find is to try_ . Just make a project in Android Studio with min SDK as 21. You'll find the MainActivity is extended to **Activity** that means you are not importing any of the compat libraries as they are not needed for min SDK 21. But that approach is actually not very useful, your app should work with minimum possible API. Thats why compat libraries are there, they give almost all functionalities of the native library. The thing is which functionality you want in the app which is not there in compat libraries. If there are none, dont leave compat. They are the best part. – Avinash Aug 12 '15 at 20:20
  • That kind of solved the mystery for me! Thanks, sir. – Jesse Aug 12 '15 at 20:22