New Directory vs New Folder in Android Studio

前端 未结 1 542
陌清茗
陌清茗 2021-02-01 20:03

What is the difference between creating a new directory and creating a new folder in Android Studio?

Here is an image of the menu choices:

相关标签:
1条回答
  • 2021-02-01 20:30

    Short answer

    Use folder when adding a folder to an Android Studio project. This is what Android Studio calls them. Directory is what IntelliJ calls a folder. Android Studio is built on top IntelliJ so there is some naming confusion.

    Long answer

    Although there is a technical difference between a folder and a directory (see here and here), they are often (correctly or incorrectly) used interchangeably. This can be seen even in the titles of these two SO questions:

    • Setting a custom assets directory for unit testing in Android Studio
    • Adding an assets folder in Android Studio

    This can be confusing to new users of Android Studio when they see both choices in the menu structure. Further confusion results when users add a new directory and then it doesn't show up in the Android folder view. See these questions for example:

    • Android Studio: Newly Created Directory Not Appearing In Folders View
    • New created "values" folder is not visible in Android Studio

    The folders actually do show up if you select the Project or Packages view from the menu:

    enter image description here

    However if you want an Android folder to show up automatically in the Android view you need to right click and use New > Folder > Assets folder (if you are adding an assets folder). You could then add a subfolder like "fonts" to this by choosing the New > Directory option.

    Android Studio is built on top of IntelliJ IDEA. IntelliJ itself has a menu option to add a directory (as you can see here). But Android stores files in what it calls folders. So when these two platforms are put together in Android Studio, there gets to be some naming confusion. (This is my interpretation, but perhaps they really are trying to differentiate the subtle differences between directory and folder.)

    You can see from your menu image that there is also an "Android resource directory" option. (You got that by right clicking on the res directory/folder rather than a subdirectory.) You would use this to add resource folders such as raw, menu, values, etc.

    0 讨论(0)
提交回复
热议问题