How change icons color on API < 21? - android

Because API 19 (KitKat) is still very popular, it's a good choice to support this release. However, it does not support many features, such as backgroundTint and ImageTint. This puts me in various compatibility issues and design choices.
I have several icons to load on a screen and I'm currently using setImageTintList to make the app dynamic.
The "faces" and "bucks" should change color according to the element in a recyclerView. What is the best way to support this function on systems with API <21?

I'm not sure what APIs you exactly mean by saying "backgroundTint and ImageTint", but there's a compatibility ViewCompat class which will backport some functionality up to API 4.
Amongst them are:
setBackgroundTintList(View, ColorStateList)
setBackgroundTintMode(View, ColorStateList)
If by saying "ImageTint" you meant android:tint or setImageTintList(), then this answers your question.

Related

Problems using App Compat theme instead of Material Theme [duplicate]

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

Not sure if I should be using AppCompat, regarding themes, bars, etc

I have been really confused on this. I want to be able to have a lot of people use my app, but as of this post, this seems difficult unless you set your minimum API down to 16-17 or so.
Even if I am setting my API to this level, is there any point to me using things like AppCompatActivity / the Support Library?
If I want to use a Material theme, do I either have to set minimum API to 21 or use AppCompat?
Are "ActionBars" still a thing, or are they deprecated? I'm trying to find something that will allow me to display the bar on all preference screens (including nested screens). I'm also trying to include icons in both the bar and the preference items.
So I am unsure what API I need to use / what libraries to use.
Your question is similar to this previously asked question
Should I use AppCompat v7 if minsdk is 14
AppCompat libraries allow you to provide features and capabilities that are in later releases of Android to earlier releases that dont have them in their SDK versions. Theme features and capabilities are part of this, but certainly not limited to that. Example that you already stated is the material design one. If you want widgets and views that are introduced in SDK 21+ supported in say API 15 (ICS) then you would use AppCompat 21+. However, features that are in AppCompat +7 (example AnimatedVectorDrawable) would not be needed since Api 15 would already support that.
So effectively it depends on the feature you want to support and the minimum SDK you are targeting.
Hope that helps!

Programming for Android 5 without AppCompat

I understand that it is considered good practice to program for Android using the AppCompat support libraries for backwards compatibility. However, for this specific project, the minimum API level I am to support is Android 5.0 (level 22).
However all information I can find for new Lollipop features always points towards the AppCompat support libraries. Must I do this, or are there vanilla equivalents that do not require AppCompat themes, classes or attention to backwards compatibility (ie. a plain CoordinatorLayout in layout XML instead of android.support.design.widget.CoordinatorLayout)?
First, Andorid 5.0 is API 21. If you set the min SDK to 21, most features like material design theme comes by default, you don't need any libraries. But I think the CoordinatorLayout is only in the com.android.support:design library, you have to include the library to use it.
You will need to use various support libs for certain functionality.
The CoordinatorLayout exists in the design library, and not in the OS framework.
This can actually be quite useful. Use of the design library means you can use these components independently from the OS version of the user's device. Meaning you can get updated functionality without the user updating their OS.
And won't experience breaking API differences depending on what OS the user runs.

AppCompat Library Disadvantages

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.

Implementing recently introduced Android design and UI guidelines on 2.x versions

Considering Android Design Guidelines announcement what is the best way to make apps which are compliant with them on Android 2.x phones? E.g. what is the best way to implement the ActionBar pattern?
ActionbarSherlock is a starting point. It includes the compatibility libraries from Google and comes provided as a project rather than JAR offering greater flexibility, should you need to alter anything. Version 4 is on the way which will also include ICS stuff.
As far as I am aware I believe ABS is backward compatible to 1.6, and makes use of the minSdkVersion and targetSdkVersion. It uses an extended version of the holo theme to create a light and dark version that includes the extra ActionBar goodness, which in turn you can extend to style your app.
I recorded a tutorial on YouTube to get people started.
I think it's better to use the compatibilty libraries directly, instead of another library based on those. Additionally, refer to the Google I/O App as stated at the bottom of the first link I gave. You can find the best practices about implementing a UI for several devices with compatibility libraries.
I found ActionBarSherlock to be pretty good. It will emulate ActionBar on older devices and use the native one on modern ones. It's an extension to Android compatibility library - so you will also get fragments and other ICS stuff.

Categories

Resources