Android 框架小部件与其 AppCompat 版本之间的区别

Difference between Android Framework widgets and their AppCompat version

我最近注意到 Android 中大多数视图类型都有 AppCompat 版本,例如 ListView / ListViewCompatButton / AppCompatButton等等

对于这些比较简单的View(不算SwitchCompat之类的),它们和AndroidFramework版本有什么区别?我还没有找到关于此事的任何文件...

我很想知道选择任一版本的后果,以及选择一个版本是否比另一个版本有任何优势。

具体来说:

我从普通版本更改为 AppCompat 版本,希望使用主题中的颜色并且在 Lollipop 和 pre-lollipop 上看起来相同,但它对某些视图(例如 ListView)产生了相反的效果

AppCompat 为旧版本的 API 提供一致的 UI 支持,回到 API v7。 来自 Documentation

appcompat 中可用的色调感知小部件的完整列表

AppCompatAutoCompleteTextView
AppCompatButton
AppCompatCheckBox
AppCompatCheckedTextView
AppCompatEditText
AppCompatMultiAutoCompleteTextView
AppCompatRadioButton
AppCompatRatingBar
AppCompatSpinner
AppCompatTextView

ListViewCompat 是 ListView 的子类 其他相同


已编辑:

why both class available in framework or How Android Support Library work?

如果您使用 AppCompatActivity,那么当您在布局中使用 ImageView 时,将自动使用 AppCompatImageView

来自AppCompatImageView AppCompatEditText AppCompatButton

按钮与 AppCompatButton

This will automatically be used when you use Button in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

ImageView 与 AppCompatImageView

This will automatically be used when you use ImageView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

EditText 与 AppCompatEditText

This will automatically be used when you use EditText in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

同样的规则也适用于其他 appcompat 视图