问题描述
android.support.v7.app.AppCompatActivity
加入到最新的V7支持库作为一项新功能昨天。
android.support.v7.app.AppCompatActivity
was added into the latest v7 support library as a new feature yesterday.
据说 ActionBarActivity
已pcated赞成德$ P $新 AppCompatActivity
和 AppCompatActivity
对于使用支持库操作栏功能活动的基类。那么,什么是 AppCompatActivity
新功能了 ActionBarActivity
?做 AppCompatActivity
有超过 ActionBarActivity
什么改进?什么是 AppCompatActivity
的优势是什么?可能有人提供了几样?
It is said that ActionBarActivity
has been deprecated in favor of the new AppCompatActivity
and that AppCompatActivity
is base class for activities that use the support library action bar features. So, what are new features of AppCompatActivity
over ActionBarActivity
? What enhancements do AppCompatActivity
have over ActionBarActivity
? And what are advantages of AppCompatActivity
? Could somebody supply a few samples?
任何提示的AP preciated。而在此先感谢。
Any tips are appreciated. And thanks in advance.
PS:什么最让我吃惊的是, AppCompatActivity
这是从 android.support.v4.app.FragmentActivity
是直接父类 ActionBarActivity
的!我的意思其实现在 ActionBarActivity
可以做任何事情, AppCompatActivity
可以做,没有安卓为何推出后?
PS: what surprised me most is that AppCompatActivity
which is extended from android.support.v4.app.FragmentActivity
is the direct parent class of ActionBarActivity
! I mean actually now that ActionBarActivity
can do anything that AppCompatActivity
can do, why did Android pushed out the latter?
与此同时,我看到了一篇博客文章,指出:这是不是从 ActionBarActivity
重命名为 AppCompatActivity
,内部的逻辑 AppCompat
可通过 AppCompatDelegate
的,那么什么是的内部逻辑 AppCompat
的的?什么 AppCompatDelegate
吗?可能有人张贴一些codeS样?
Meanwhile, I saw a blog post that states: "It's not a rename from ActionBarActivity
to AppCompatActivity
, the internal logic of AppCompat
is available via AppCompatDelegate
", so what's the "internal logic" of AppCompat
? What can AppCompatDelegate
do? Could somebody post some codes about this?
推荐答案
由于克里斯写道,对 ActionBarActivity
(一延伸 AppCompatActivity 类)是一种使用安全向后兼容性一流。其德precation只是一个提示你使用新的 AppCompatActivity
,而不是直接。 AppCompatActivity
是一个新的,更通用的实现,它使用 AppCompatDelegate
类在内部。
As Chris wrote, the new deprecated version of ActionBarActivity
(the one extending AppCompatActivity
class) is a safe to use backward compatibility class. Its deprecation is just a hint for you to use new AppCompatActivity
directly instead. AppCompatActivity
is a new, more generic implementation which uses AppCompatDelegate
class internally.
如果你开始一个新的发展,那么你应该宁可用新的 AppCompatActivity
类的时候了。如果你有机会来更新应用程序,然后替换 ActionBarActivity
通过新的活动也是如此。否则,你可以留德precated活动,会有的行为没有什么区别。
If you start a new development, then you should rather use new AppCompatActivity
class right away. If you have a chance to update the app, then replace ActionBarActivity
by the new activity as well. Otherwise you can stay with deprecated activity and there will be no difference in behavior.
关于 AppCompatDelegate
,它可以让你有新的有色部件在活动,这既不是 AppCompatActivity
和 ActionBarActivity
。
Regarding AppCompatDelegate
, it allows you to have new tinted widgets in an activity, which is neither AppCompatActivity
nor ActionBarActivity
.
例如,你继承外部库,这反过来,做一个活动的不可以从 AppCompatActivity
继承,但是你想这种活动有有色材料部件(意见)。为了做到这一点,你需要创建 AppCompatDelegate
您的活动里面的一个实例,覆盖该活动的方法,如 addContentView()
,的setContentView()
等(见 AppCompatDelegate
的javadoc方法的完整列表),以及内部的覆盖方法转发呼叫内 AppCompatDelegate
实例。 AppCompatDelegate
将完成剩下的和你的旧时代的活动将物化。
For instance, you inherit an activity from an external library, which, in turn, does not inherit from AppCompatActivity
but you want this activity to have tinted materials widgets (views). To make it happen you need to create an instance of AppCompatDelegate
inside your activity, override methods of that activity like addContentView()
, setContentView()
etc. (see AppCompatDelegate
javadoc for the full list of methods), and inside those overridden methods forward the calls to inner AppCompatDelegate
instance. AppCompatDelegate
will do the rest and your "old-fashion" activity will be "materialized".
这篇关于什么是AppCompatActivity的增强了ActionBarActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!