Android 为什么我的 Activity 会扩展 ActionBarActivity?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22392384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does my Activity extend ActionBarActivity?
提问by Marcelo Alarcon
I downloaded the latest SDK version and when I created a new Android project the MainActivity
that automatically generated extends ActionBarActivity
, but I want to extend Activity
.
我下载了最新的 SDK 版本,当我创建一个新的 Android 项目时MainActivity
,自动生成的 extends ActionBarActivity
,但我想扩展Activity
.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
采纳答案by jstn
If you want to extend Activity class, you may check "Empty Activity" during the project creation trajectory.
如果要扩展Activity类,可以在项目创建轨迹中勾选“Empty Activity”。
回答by donfuxx
ActionBarActivityis for backwards-compatibility. So the Android Actionbar will also work on older devices, see documentation.
ActionBarActivity是为了向后兼容。因此 Android Actionbar 也适用于较旧的设备,请参阅文档。
Base class for activities that use the support library action bar features.
You can add an ActionBar to your activity when running on API level 7 or higher by extending this class for your activity and setting the activity theme to Theme.AppCompat or a similar theme.
使用支持库操作栏功能的活动的基类。
通过为您的活动扩展此类并将活动主题设置为 Theme.AppCompat 或类似主题,您可以在 API 级别 7 或更高级别上运行时向您的活动添加 ActionBar。
It is a subclassof FragmentsActivity and FragmentsActivity extendsActivity. ==> so don't worry all things you could do with normal Activities you can also do with an ActionBarActivity.
它是FragmentsActivity的子类,FragmentsActivity扩展了Activity。==> 所以不要担心你可以用普通活动做的所有事情,你也可以用 ActionBarActivity 做。
回答by Hackbal Teamz
Simply Replace ActionBarActivityto ActivityThen go to top of the code and replace import android.support.v7.app.ActionBarActivity;to import android.app.Activity;
只需将ActionBarActivity替换 为Activity然后转到代码顶部并替换import android.support.v7.app.ActionBarActivity; 以进口android.app.Activity;
回答by Vamsi Tallapudi
You can simply replace the ActionBarActivity with Activity since ActionBarActivity is an extension of Activity. You can refer the class hierarchy here: http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html
您可以简单地将 ActionBarActivity 替换为 Activity,因为 ActionBarActivity 是 Activity 的扩展。您可以在此处参考类层次结构:http: //developer.android.com/reference/android/support/v7/app/ActionBarActivity.html
回答by SeahawksRdaBest
My guess is when you created the app, you choose the Action bar setting in eclipse. Please notice ActionBarActivityis an extension of Activity, so all features present in Activity will be present in ActionBarActivity.
我的猜测是当您创建应用程序时,您选择了 eclipse 中的操作栏设置。请注意 ActionBarActivity是 Activity 的扩展,因此 Activity 中存在的所有功能都将出现在 ActionBarActivity 中。
回答by Noorul
Nowadays latest Android SDK ActionbarActivity only. which is from IDE and Google. No Problem with that. ActionBarActivity Facilitate to your application which works on Older API also. Don't worry. That's is not problem.
现在只有最新的 Android SDK ActionbarActivity。这是来自 IDE 和谷歌。没问题。ActionBarActivity 促进您的应用程序也适用于旧 API。别担心。那不是问题。