38

What is the difference between an AppCompat view component and a standard/default view component?

For example, the difference between an AppCompatEditText, and an EditText, or between an AppCompatButton and a Button.

Looking at the developer docs for android.support.v7.widget, the AppCompat view components are described as "tint aware", but is this the only difference, and what exactly does this do?

Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125
  • 3
    "what exactly does this do?" -- `appcompat-v7`, as with `Theme.Material`, supports the notion of a custom theme defining colors, like `colorPrimary` and `colorAccent`. Native `Theme.Material` widgets on Android 5.0+, and supported widgets in `appcompat-v7`, will use those colors in accordance with the Material Design guidelines. – CommonsWare May 31 '15 at 11:33
  • Thanks @CommonsWare. If you post this as an answer I would be able to accept it. – Farbod Salamat-Zadeh May 31 '15 at 11:36
  • Well, it does not fully answer your question. I have not done a systematic review of all the `appcompat-v7` widgets (particularly with the recent update) to know what else, besides tinting, may be different about them. – CommonsWare May 31 '15 at 11:37

3 Answers3

28

When you are using a Button or an EditText you are actually using AppCompatButton and AppCompatEditText. From the official documentation of the AppCompatEditText.

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

Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125
Sid
  • 14,176
  • 7
  • 40
  • 48
  • 1
    Link: https://developer.android.com/reference/android/support/v7/widget/AppCompatEditText.html – Mu Sa Sep 06 '16 at 07:15
  • 2
    This is only true when your `Button` (or whatever view) is hosted in an activity which extends from `AppCompatActivity`. https://developer.android.com/reference/android/support/v7/widget/AppCompatButton – boltup_im_coding Jul 09 '19 at 00:10
  • This is only apply to AppCompatActivity: https://medium.com/@hxlich/when-to-use-appcompat-views-to-write-custom-views-f5ca00df8d82?source=friends_link&sk=448a65fd4c2108a050e7613c11b6183f – Harry Han Aug 31 '20 at 00:00
13

What is the difference between an AppCompat view component and a standard/default view component?

AppCompat View Component supports compatible features on older version of the platform.

the AppCompat view components are described as "tint aware", but is this the only difference, and what exactly does this do?

Although most of the AppCompatView only difference is it allows dynamic tint and background tint. Tint aware is not the only difference, each AppCompatView has its own differences, for example.

  • AppCompatEditText vs EditText

Allows textAllCaps style attribute up to Gingerbread.

  • AppCompatSpinner vs Spinner

Setting the popup theme using popupTheme.

You can dig down each view difference in Android docs.

However, as Sid / Docs says, you don't have to specify this on your layouts since it will automatically converted to AppCompat views. But, if you want to create custom view, you should use AppCompat Views, or else this bug will happens.

Community
  • 1
  • 1
aldok
  • 17,295
  • 5
  • 53
  • 64
0

well one of differences that i have noticed , in order to change the background of a normal Button , you have to modify the XML ( to NoActionBar.. android:theme="@style/Theme.AppCompat.Light.NoActionBar" to android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"

whatever all i want to say is it difficult to work with buttons than the AppCompat version ).

so the use of androidx.appcompat.widget.AppCompatButton is somehow considered good because you will avoid a lot of little problems using the androidx library.

Minato
  • 21
  • 2