Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use an AppCompatView vs a normal Android view

What is the difference between using them, and when should they be used?

An example of the documentation for an AppCompatView is:

A tint aware EditText. This will automatically be used when you use EditText in your layouts. You should only need to manually use this class when writing custom views

Why should the AppCompatView only be used for custom views?

There is a similar question, but I am looking for a good explanation for why the AppCompatView should only be used for custom views.

like image 311
NaiveBz Avatar asked Jan 04 '16 23:01

NaiveBz


1 Answers

Some material design features like the material theme and custom activity transitions are only available on Android 5.0 (API level 21) and above. However, you can design your apps to make use of these features when running on devices that support material design and still be compatible with devices running previous releases of Android.

Que-> Why the AppCompatView should only be used for custom views.

Answer -> In simple terms AppCompatView is used for maintaining compatibility. If your app uses the Material theme as with Theme.Material but does not provide an alternative theme, your app will not run on versions of Android earlier than 5.0.

If the layouts that you design according to the material design guidelines do not use any of the new XML attributes introduced in Android 5.0 (API level 21), they will work on previous versions of Android. Otherwise, you can provide alternative layouts. You can also provide alternative layouts to customize how your app looks on earlier versions of Android.

Making backwards compatible material design Android applications is much easier with AppCompat, especially when you understand how its styles and themes are working together to dynamically tint the user interface.

With AppCompat, you should spend less time fiddling with assets and backwards compatibility, and more time focusing on actually building your application.

Currently, new projects created through Android Studio incorporate this library by default.

Note: This library depends on the v4 Support Library.

Below are few links for references

  1. Android Material Themes Made Easy With AppCompat
  2. Migrating to the AppCompat Library
  3. Getting Material Design for Pre-Lollipop Devices with AppCompat v21
like image 127
Mohammad Tauqir Avatar answered Oct 14 '22 15:10

Mohammad Tauqir