android – 当应用程序的minSdkVersion为21时,我的活动应该扩展什么?

我是 AndroidAndroid Studio的新手.我创建了一个新项目,我已将minSdkVersion指定为21并将目标指定为23.

完成AS创建活动后,我发现默认情况下MainActivity正在扩展AppCompatActivity.

我读到了AppCompatActivity here

它表示它是使用support library操作栏功能的活动的Base类.

现在我的问题是:

>由于我的应用程序的minSdkVersion为21,为什么我需要我的活动来扩展AppCompatActivity?
>为什么AS使我的活动默认扩展AppCompatActivity?
>考虑到我的minSdkVerion,我的活动是否有必要扩展AppCompatActivity或只是扩展Activity就足够了?
>如果我的行为不扩展AppCompatActivity,我会想念什么?

任何解释都会非常有用.谢谢

解决方法

如果您使用操作栏,我认为您应该扩展AppCompatActivity

Read more here

Beginning with Android 3.0 (API level 11),all activities that use the default theme have an ActionBar as an app bar. However,app bar features have gradually been added to the native ActionBar over varIoUs Android releases. As a result,the native ActionBar behaves differently depending on what version of the Android system a device may be using. By contrast,the most recent features are added to the support library’s version of Toolbar,and they are available on any device that can use the support library.

For this reason,you should use the support library’s Toolbar class to implement your activities’ app bars. Using the support library’s toolbar helps ensure that your app will have consistent behavior across the widest range of devices. For example,the Toolbar widget provides a material design experience on devices running Android 2.1 (API level 7) or later,but the native action bar doesn’t support material design unless the device is running Android 5.0 (API level 21) or later.

相关文章

以下为个人理解,如错请评 CE: 凭据加密 (CE) 存储空间, 实际路径/data/user_ce/ DE: 设备加密 (DE) 存...
转载来源:https://blog.csdn.net/yfbdxz/article/details/114702144 用EventLog.writeEvent打的日志(或...
事件分发机制详解 一、基础知识介绍 1、经常用的事件有:MotionEvent.ACTION_DOWN,MotionEvent.ACTION...
又是好久没有写博客了,一直都比较忙,最近终于有时间沉淀和整理一下最近学到和解决的一些问题。 最近进...
Android性能优化——之控件的优化 前面讲了图像的优化,接下来分享一下控件的性能优化,这里主要是面向...
android的开源库是用来在android上显示gif图片的。我在网上查了一下,大家说这个框架写的不错,加载大的...