在 Eclipse 中将 Activity 添加到 Android 项目的最佳方法?

2022-01-20 00:00:00 ide android eclipse android-activity

向现有 Android 项目添加活动时,我手动创建了一个新类 - 这是最好/首选的方式吗?其他人是怎么处理的?

When adding an activity to an existing Android project, I manually create a new class - is that the best / preferred way? How do others handle that?

推荐答案

您可以使用新建类"对话框,但需要手动执行其他步骤(例如,向清单文件添加条目).如果您希望这些步骤自动化,您可以通过清单编辑器创建活动,如下所示:

You can use the "New Class" dialog, but that leaves other steps you need to do by hand (e.g. adding an entry to the manifest file). If you want those steps to be automated, you can create the activity via the manifest editor like this:

  1. 在包资源管理器中双击 AndroidManifest.xml.
  2. 点击清单编辑器的应用程序"标签
  3. 点击应用程序节点"标题下的添加.."(屏幕左下角)
  4. 从弹出的对话框中的列表中选择 Activity(如果有选项,您想创建一个新的顶级元素)
  5. 点击属性"标题下的名称*"链接(窗口右下角)为新活动创建一个类.

当您从新课程对话框中单击完成"时,它将带您进入新的活动课程,以便您开始编码.

When you click Finish from the new class dialog, it'll take you to your new activity class so you can start coding.

五个步骤可能看起来很多,但我只是想在这里更加详细,以便清楚.实际操作时非常快.

Five steps might seem a lot, but I'm just trying to be extra detailed here so that it's clear. It's pretty quick when you actually do it.

相关文章