如何在Android Studio中向现有项目添加新活动?

时间:2023-01-27 10:44:12

In Eclipse you just clicked the new button and select the android activity to add new activity. But Android Studio is a bit diferent; I couldn't find out how to add new activity to the project.

在Eclipse中,您只需单击新按钮并选择要添加新活动的android活动。但Android Studio有点不同;我无法找到如何向项目添加新活动。

4 个解决方案

#1


107  

To add an Activity using Android Studio.

使用Android Studio添加活动。

This step is same as adding Fragment, Service, Widget, and etc.. Screenshots provided.

此步骤与添加片段,服务,窗口小部件等相同。提供了屏幕截图。

[UPDATE] In Android Studio 0.5.4

[更新]在Android Studio 0.5.4中

  1. In your Main Application project, go to your src folder.

    在Main Application项目中,转到src文件夹。

    如何在Android Studio中向现有项目添加新活动?

  2. Double click the src to expand.

    双击src以展开。

    如何在Android Studio中向现有项目添加新活动?

  3. Right click main or java folder. New > Activity.

    右键单击main或java文件夹。新>活动。

    如何在Android Studio中向现有项目添加新活动?


[Android studio 0.5.3 and below]

[Android studio 0.5.3及以下]

  1. On your project, go to java folder (src > main) > right click either the java folder or a package name > New > Android Component.
  2. 在您的项目中,转到java文件夹(src> main)>右键单击java文件夹或包名称> New> Android Component。
  3. Now, the next step would be easy for you. Cheers! :)
  4. 现在,下一步对您来说很容易。干杯! :)

To add a Service, Application, Remote Interface or a BroadcastReceiver, just do the same step.

要添加服务,应用程序,远程接口或BroadcastReceiver,只需执行相同的步骤即可。

#2


13  

In Android Studio 2, just right click on app and select New > Activity > ... to create desired activity type.

在Android Studio 2中,只需右键单击应用并选择新建>活动> ...即可创建所需的活动类型。

如何在Android Studio中向现有项目添加新活动?

#3


5  

I think natually do it is straightforward, whether Intellij IDEA or Android Studio, I always click new Java class menu, and then typing the class name, press Enter to create. after that, I manually typing "extends Activity" in the class file, and then import the class by shortcut key. finally, I also manually override the onCreate() method and invoke the setContentView() method.

我认为自然是直截了当,无论是Intellij IDEA还是Android Studio,我总是点击新的Java类菜单,然后输入类名,按Enter键进行创建。之后,我在类文件中手动键入“extends Activity”,然后通过快捷键导入类。最后,我还手动覆盖onCreate()方法并调用setContentView()方法。

#4


1  

In Android Studio, go to app -> src -> main -> java -> com.example.username.projectname

在Android Studio中,转到app - > src - > main - > java - > com.example.username.projectname

Right click on com.example.username.projectname -> Activity -> ActivityType

右键单击com.example.username.projectname - > Activity - > ActivityType

Fill in the details of the New Android Activity and click Finish.

填写New Android Activity的详细信息,然后单击Finish。

Viola! new activity added to the existing project.

中提琴!新活动已添加到现有项目中。

#1


107  

To add an Activity using Android Studio.

使用Android Studio添加活动。

This step is same as adding Fragment, Service, Widget, and etc.. Screenshots provided.

此步骤与添加片段,服务,窗口小部件等相同。提供了屏幕截图。

[UPDATE] In Android Studio 0.5.4

[更新]在Android Studio 0.5.4中

  1. In your Main Application project, go to your src folder.

    在Main Application项目中,转到src文件夹。

    如何在Android Studio中向现有项目添加新活动?

  2. Double click the src to expand.

    双击src以展开。

    如何在Android Studio中向现有项目添加新活动?

  3. Right click main or java folder. New > Activity.

    右键单击main或java文件夹。新>活动。

    如何在Android Studio中向现有项目添加新活动?


[Android studio 0.5.3 and below]

[Android studio 0.5.3及以下]

  1. On your project, go to java folder (src > main) > right click either the java folder or a package name > New > Android Component.
  2. 在您的项目中,转到java文件夹(src> main)>右键单击java文件夹或包名称> New> Android Component。
  3. Now, the next step would be easy for you. Cheers! :)
  4. 现在,下一步对您来说很容易。干杯! :)

To add a Service, Application, Remote Interface or a BroadcastReceiver, just do the same step.

要添加服务,应用程序,远程接口或BroadcastReceiver,只需执行相同的步骤即可。

#2


13  

In Android Studio 2, just right click on app and select New > Activity > ... to create desired activity type.

在Android Studio 2中,只需右键单击应用并选择新建>活动> ...即可创建所需的活动类型。

如何在Android Studio中向现有项目添加新活动?

#3


5  

I think natually do it is straightforward, whether Intellij IDEA or Android Studio, I always click new Java class menu, and then typing the class name, press Enter to create. after that, I manually typing "extends Activity" in the class file, and then import the class by shortcut key. finally, I also manually override the onCreate() method and invoke the setContentView() method.

我认为自然是直截了当,无论是Intellij IDEA还是Android Studio,我总是点击新的Java类菜单,然后输入类名,按Enter键进行创建。之后,我在类文件中手动键入“extends Activity”,然后通过快捷键导入类。最后,我还手动覆盖onCreate()方法并调用setContentView()方法。

#4


1  

In Android Studio, go to app -> src -> main -> java -> com.example.username.projectname

在Android Studio中,转到app - > src - > main - > java - > com.example.username.projectname

Right click on com.example.username.projectname -> Activity -> ActivityType

右键单击com.example.username.projectname - > Activity - > ActivityType

Fill in the details of the New Android Activity and click Finish.

填写New Android Activity的详细信息,然后单击Finish。

Viola! new activity added to the existing project.

中提琴!新活动已添加到现有项目中。