I am trying to support devices down to API level 9 by using the AppCompat library. I am trying to theme the ActionBar using the example theme from Google but it keeps telling me that any item named android:action* requires API level 11 (current min is 9). I am targeting 18. If I use the stuff directly from the example why is it breaking? And can anyone help me figure out how to theme the ActionBar using the AppCompat library from API level 9?
The android:action* items are only available with API 11 and above. In order to support different API levels, Android contains various values directories. If you look at your project's folder structure, you will most likely see directories for res/values and res/values-11 and perhaps a few other ones. As you might have guessed, the 11 stands for API 11, which means that themes that are only available in API 11 and above should be included here. The values directory is your base one.
Therefore, for your example, you need to split up the themes file into two different ones. The parts that contain android:action* should be in a themes file in the values-11 folder, and the other ones can stay in the base values folder. Android takes care of automatically choosing the proper theme.
You should really read this, especially the parts near the bottom about applying themes. It discusses how you can apply themes to different API levels.
The function you are trying to use is only available from API 11 up.
You won't be able to use in devices that have API level 9 like you wanted to.
requires API level 11 (current min is 9)
You can run the example in devices with Android 3.0 and up, but for that you will have to change your Manifest file minSdkVersion to at least 11.
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
Try to remove all the items with android:action* and leave only those with action* (without the android namespace).
This works for me but I got my style from this wonderful style generator for action bar: http://jgilfelt.github.io/android-actionbarstylegenerator/
Related
This question already has an answer here:
Material Design, AppCompat, and Backwards Compatibility
(1 answer)
Closed 6 years ago.
I would like to use Material theme for my app and target from Jelly Bean to "M".
What's the correct recommendation ?
1. Use appcompat theme on api levels below 21 and use standard material them on 21 and above
2) Simply use appcompat on all the api levels.
Will I be missing anything if I simply use appcompat on all api levels ?
You would use only the AppCompat themes for all. For most stylings, they have their own implementations that mimic more modern approaches. For things that can't be mimicked, they just simply don't do it or move to the default (one that comes to mind is the Ripple effect. 21+ devices it will use Ripple, but on others it will default to the standard button selector). If they can use native approaches, then they will use those instead.
On some cases though, you may need to create styles that contain attributes which unique to a certain API level. In which case you need to create a layout-v## folder where ## is the API level to support. Then put in a Style with the same name as one in the lower layout folder. Android will choose the appropriate folder. The same can be done for any other resource folder.
Use AppCompat for everything, there is built in functionality to handle if you are using < 21 or >= 21.
Really the only time you should use the standard Material Theme is if your base API you support is 21+ but even then you will eventually use app compat for new things that get added
Some material design are only supported starting from android 21 API , so for this purpose we need to provide alternative styles that will work on devices running earlier version . (like they say in documentation ) .
for example :
res/values/styles.xml
res/values-v21/styles.xml
They also have mentioned V7 support library that includes Material design styles .
From here I am little bit confused !
Suppose that my default theme extends from Theme.AppCompat .
Why Should I provide an alternative style for 21 api knowing that Theme.AppCompat is made for compatibility ?
You should do so to use functionalities from api 21 that does not previously exist.
For exemple, on api 21 and later you can make the statusbar translucent, and this is not done by default with the appcompat, because that's not the default behavior.
In a general sense, AppCompat back ports everything that you will generally need to worry about (with new features added all the time). AppCompat itself is doing that alternative style heavy lifting for you.
Start with AppCompat and only create an alternative style if you run in to a specific feature that you need (you probably won't).
I'm a new Android developer who is trying to find the best balance for API level support. I think my indecision stems from a lack of understanding of the benefits and disadvantages of using the AppCompat Library over newer Android features such as Holo themes and the action bar.
Of course, I know that Holo is unavailable before API Level 14 and the Action Bar is unavailable before API Level 11. If I want to make my apps available to the broader Android userbase, I will need to lower my minSdkVersion and use the AppCompat Library.
My question is, are there any significant recent features of the Android OS that just aren't supported or are unable to be implemented through the AppCompat Library? Adding on to that, if you set your minSdkVersion to say API Level 7 and build your app with support for AppCompat (say, with your app themes being Theme.AppCompat.Light), will devices running an API greater than 11 or 14 for example use default Holo or action bar features or be restricted to AppCompat? I'd like to know if supporting older APIs will disadvantage users with newer and more capable devices.
Anyway, regardless of the outcome, I'll probably still go for supporting say API 7-8. This is more of a curiosity question on my part. I hope it makes sense!
Thanks, Klep
AppCompat should add functionality of the latest API to older APIs when needed. For instance, lollipop added the CardView class, which can be used in older Android APIs when AppCompat is used, with some minor differences (some of the Android L animations may not apply on older versions of Android for example). It is recommended to use AppCompat in most cases, since more users will be able to run your app when you do (depending on your MinSdkVersion). If you want to know what classes you can access in AppCompat, you can take a look at the features here.
Regarding the Styles: through Platform.AppCompat style the Theme.Appcompat inherits, and then overrides some properties, from Holo (11+) or Material (21+) if these are native on the running device.
I am aiming to use android:verticalScrollbarPosition to put the scrolling bar on the left.
I know this is supported for Api 11+. If I compile with target devices being Api 16 but my min supported APi is 8. What would happen to the Api 8 users? Will it crash or will it just ignore this and display scroll bar on right?
Thanks
XML attributes introduced in newer versions of Android will simply be ignored on older platform versions. In case your layout look and feel will break because of this you might want to create separate layouts (placing them in separate layout folders) for different platform versions.
Hope this helps.
I'm just starting with Android development so bear with me. I've downloaded Android Studio, and when i start a new project it a theme called Theme.AppCompat.Light (even tough I've selected Holo Light when creating a new project). So my question is, why does android use this and what is it useful for? I've tried changing it to android:Theme.Holo.Light but it just gives me an error:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I'm using this SDK configuration:
android:minSdkVersion="7"
android:targetSdkVersion="18"
So my question is, why would you use AppCompat, and what do i have to do to enable my app to use the Holo theme.
My activity class is just the default that is generated (it extends ActionBarActivity).
Holo Themes were introduced in API level 14.
Change your android:minSdkVersion="7" to android:minSdkVersion="14"
If you want to keep it 7 at least, use this project to get the Holo themes: HoloEverywhere
That's because you use SDK 7 (Android 2.1) which knows nothing about Holo.
The Android Team provides a compatibility theme that looks (almost) like Holo.
On a side node you should switch to SKD 10 at least, It will make your life a lot easier.
See the ActionBar was introduced in API 11 so after that to make backward compatible Google released the support library. You and read about that here Android Support Library here you can also find how to use them in your app.Not only for Action Bar Google has support library for backward compatibility for many new features available on new devices and make them work on older devices.
The Default Activity when creating the project inherits from ActionBarActivity on min api level 15 or above, I changed this to Activity and now my activity inherits from Activity. Now I can change to Holo or other theme. I guess inheriting from ActionBarActivity requires appcompat theme.