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.
Related
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 have an app which runs on Android 2.3 and above.
Recently, I'm in the process of migrating it from SherlockActionBar, to AppCompat, by following guideline from What are the common issues when migrating from ActionBarSherlock to ActionBarCompat?
This is what I had done so far.
Upgrade SDK version
Change SDK from
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
to
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="22" />
Theme Upgrade
Change theme from
Theme.Sherlock.Light.DarkActionBar
to
Theme.AppCompat.Light.DarkActionBar
Code update
Following code change guideline from What are the common issues when migrating from ActionBarSherlock to ActionBarCompat?.
Note, I'm still stick to ActionBar instead of Toolbar. Eventually, I shall move the code to Toolbar. Since migration is a HUGE project. I rather done it bit by bit.
My expectation is that
App which runs on Android 2.3 till Android 4, should have old school holo design. I expect the app will look the same, as the one built using SherlockActionBar.
App which runs on Android 5+, will have new material design.
However, here's how the app before & after migration, for an 2.3 App.
Before Migration
After Migration
It seems that after migration, I can observe that
Action bar height is higher.
The dialog box OK to Cancel buttons, had changed from 3D to Material flat.
I was wondering, what should be the correct expectation on old App (App which runs on 2.3 till 4+), when we built against AppCompat, with latest SDK 22 as target? Should they look like Material app, or Holo app?
From the Support Library Features section for AppCompat:
This library adds support for the Action Bar user interface design pattern. This library includes support for material design user interface implementations.
So what you are seeing is the expected behavior- AppCompat is designed to bring the ActionBar and Material to all devices with API 7 and up.
Prior to the release of version 21 of AppCompat alongside Android Lollipop (API 21), AppCompat did indeed provide an ActionBar with Holo theming. However, it never styled other components, only ever the ActionBar itself.
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 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/
I was using Theme.Holo as parent in my application before trying to target lower versions of Android OS. To adapt my application to older versions, I have to use ActionBarSherlock library. But it requires the theme of the application be one of ActionBarSherlock's own themes (Theme.Sherlock.Light.DarkActionBar instead of Theme.Holo).
I still need to use Theme.Holo. But it is not possible by default.
Are there any modifications done do make this happen?
Holo theme is not known to older versions of android, ActionBarSherlock defines necessary parts of Holo Style for ActionBar.
If you need to have Same look on older versions (Although it doesn't look native) you can use HoloEverywhere Library.
As an alternative you can generate Holo-Styled drawables using Android Holo Colors Generator Project