为什么我要使用AppCompatActivity,而不是一个独立的工具栏创建活动的应用程序栏? [英] Why should I use AppCompatActivity instead of a standalone Toolbar to create an Activity's app bar?

查看:475
本文介绍了为什么我要使用AppCompatActivity,而不是一个独立的工具栏创建活动的应用程序栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有在API活动创建一个应用栏21+使用工具栏的两个主要途径。

There are two principal ways of creating an app bar for an activity in API 21+ using the Toolbar.


  1. 创建延伸AppCompatActivity一个活动,然后按照说明这里

创建一个独立的工具栏它作为一个应用程序栏(使用 android.support.v7.widget定义XML工具栏。工具栏),然后膨胀的菜单到它是这样的:`toolbar.inflateMenu(R.menu.homeview_menu_common);

Create a standalone Toolbarwhich acts as an app bar (define the Toolbar in xml using android.support.v7.widget.Toolbar) and then inflate a menu into it like this: ` toolbar.inflateMenu(R.menu.homeview_menu_common);

我的问题是:什么是做一个比其他的优点和缺点`

My question is: what are the benefits and drawbacks of doing one over the other?`

这个话题一个相关的问题也可以在这里(<一发现href=\"http://stackoverflow.com/questions/33358046/how-can-an-activity-use-a-toolbar-without-extending-appcompatactivity\">How可以活动使用工具栏不延长AppCompatActivity )

A related question to this topic can also be found here (How can an activity use a Toolbar without extending AppCompatActivity)

推荐答案

简短的回答:不,你应该让你的活动延长AppCompatActivty

Short answer: No you should make your activity extend AppCompatActivty

您可以创建一个工具栏没有AppCompatActivty但除了一个应用栏的应用程序兼容性也带来了支持库,让你的材料设计添加到您的应用程序会早在Android的API的7级。

You can create a toolbar without AppCompatActivty but besides an app bar the AppCompat also brings with it the support libraries that allow you to add material design to your app going as far back as API level 7 of Android.

除非有不使用应用程序兼容性所有Activites应该扩展AppCompatActivty到材料应用模型具体原因。

Unless there is a specific reason for not using AppCompat all your Activites should extend AppCompatActivty to model a Material app.

这篇关于为什么我要使用AppCompatActivity,而不是一个独立的工具栏创建活动的应用程序栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆