If I set minAPI to 21, do I need AppCompat?
Asked Answered
C

2

10

I decided to make my minimum API version 21 for Android, but does this mean it makes no sense to use the AppCompat anymore? Just use plain Material Design / no AppCompat / etc?

Corsica answered 9/8, 2016 at 0:43 Comment(2)
You say that like nothing has changed from API 21 to 24 (things have indeed changed).Flighty
I know there have been changes. What does that have to do with anything?Corsica
F
8

No, you should always use AppCompat. This ensures that your app is already consistent across all API levels and you have access to all new APIs (such as using the Colored buttons, which was only introduced in API 23).

Many other libraries, such as the Design Support Library also require use of AppCompat.

Flighty answered 9/8, 2016 at 0:52 Comment(9)
Under what kind of scenario would one not use AppCompat?Corsica
If you're building a system app that isn't also released on the Play Store (where backward compatibility/consistent across devices doesn't matter) or a game in Unity, etc. where you aren't using the Android framework views at all.Flighty
Is extending AppCompatActivity in all my activities enough? Or should I use AppCompatActivity and all AppCompat views as well?Jenks
@Jenks - you automatically get AppCompat views when you use AppCompatActivity.Flighty
@Flighty So if you use non-AppCompat views in the layout xml file and the Java file, they will become AppCompat views at compile time if using AppCompatActivity?Jenks
@Jenks - regular views are replaced with their AppCompat equivalents at runtime if you use AppCompatActivity.Flighty
Doesn't seems true that regular views are replaed by their AppCompat equivalents at runtime. I tried on SwitchCompat vs Switch, Using Switch, it seems like it still show old view for older SDK, and new view for newer SDK, didn't switch to use SwitchCompat. Or perhaps SwitchCompat is not AppCompatSwitch? @ianhanniballake?Dnepropetrovsk
@Dnepropetrovsk - there is no such class as AppCompatSwitch, that's correct. Swich is a little different from every other component in that it wasn't available back to API 7 (which is what AppCompat used to support), hence Switch wasn't available to substitute at all. You should just always use SwitchCompat.Flighty
Thanks @ianhanniballake. That explains. Wonder if Google should deprecate Switch in the coming release, as even SwitchCompat is not inheriting from it. Maybe SwitchCompat isn't fully compatible with Activity (non AppCompat)?, so Switch is still needed for those using just Activity?Dnepropetrovsk
L
4

The one scenario where you need to use appcompat-v7 is if you want to have an action bar, and your minSdkVersion is below 11. At the moment, there is no commonly used and maintained alternative to appcompat-v7 for this.

Otherwise, appcompat-v7 is something to consider, but it is not a requirement, and there are definite costs for using it:

  • Increased fragility, with many widgets being replaced by subclasses. Your layout might call for an EditText, but AppCompatActivity will silently replace it with an AppCompatEditText, which extends EditText. In an ideal world, this would pose no problem. However, device manufacturers have had a history of messing with the standard widget implementations. Creating subclasses of standard widgets can trip over bugs introduced by the device manufacturers. I have run into this personally a lot with EditText specifically.

  • Increased app size. appcompat-v7 adds ~1MB to your APK size. As Google likes to point out, developers should aggressively try to reduce their APK size, as some users have to pay for bandwidth by the MB (so downloading an APK has cost), and some devices are pretty stingy with storage.

  • Mandated Material Design aesthetic. Google wants all apps to use Material Design, for their own political reasons. Material Design has its adherents and its detractors. Not all designers want to follow Material Design. appcompat-v7 may make it more difficult to implement non-Material Design designs, depending upon the desired deviations from Google's specification.

  • Visual dichotomy with pre-installed apps. Users of Android 4.x devices are used to the Holo theme, and many of the non-Google pre-installed apps will have Holo-based themes. For users who happen to make use of Google's apps, they will have been exposed to Material Design and may be used to it by now. And, of course, Android 5.0+ is ever-growing as a percentage of the Android device ecosystem. However, Material Design apps look out of place compared with the apps that Samsung, LG, SONY, HTC, etc. will have on their Android 4.x devices. It is unclear if Material Design is somehow so superior as to be worth the difference to the user on these devices.

Are any of these issues show-stoppers? No. So, if you want to use appcompat-v7, go right ahead. However, please understand that appcompat-v7 is a choice, one that should be made consciously and with intent.

Locate answered 15/8, 2016 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.