创建资源文件时无法添加raw类型资源,求原因解答
raw as a Resource Type When Creating a New Resource File? Hey there! Let's walk through the common reasons you're hitting this issue and how to fix them step by step:
You’re using the wrong template for resource creation
When you try to create a "new resource file" directly, templates like Values Resource File or Layout Resource File are locked to their specific types—they won’t showrawas an option becauserawis meant for unprocessed files (audio, video, plain text, etc.) that stay in their original format.
Fix: Right-click your project’sresfolder → choose New → Android Resource Directory. In the popup, set the Resource type dropdown toraw, then hit OK. Once therawfolder exists, you can drag-and-drop files into it, or right-click the folder and select New → File to add your resource directly.Your project view is set to the wrong mode
If you’re viewing your project in "Project" or "Packages" mode, the option to create arawresource directory might be hidden or not accessible through the standard workflow.
Fix: Switch to the Android view (use the dropdown in the top-left corner of the Project window). This organizes your files into the standard Android structure, making resource-specific options easy to find.Project configuration files are corrupted
Sometimes, cached data or messed-up Gradle/.ideafiles can cause missing resource options.
Fixes:- Go to File → Invalidate Caches... → select "Invalidate and Restart" to clear Android Studio’s cache and restart the IDE.
- If that doesn’t help, click the Sync Project with Gradle Files icon (the little elephant in the toolbar) to re-sync your project’s build configuration.
- As a last ditch effort, manually create the
rawfolder: navigate toapp/src/main/res, make a folder namedraw(all lowercase), and Android Studio will automatically recognize it as a valid resource directory.
内容的提问来源于stack exchange,提问作者Johanna

