Android: How to add R.raw to project?

2020-05-24 19:22发布

How I could add R.raw class to my android project? Now I haven't /res/raw folder at all (and class as well). And I can't find any tools in eclipse to do that. So how to add R.raw?

12条回答
老娘就宠你
2楼-- · 2020-05-24 19:43

You may have to restart android studio if above solutions aren't working, i restarted it and then it works.

查看更多
Evening l夕情丶
3楼-- · 2020-05-24 19:47
  • You need to right-click on res->new->Android resource directory. Make sure you select directory and not file.

  • Select raw in resource type and it automatically selects raw as the directory name.

  • Drag and drop your .mp3 music file inside the res folder. Make sure that it starts with a small letter.

查看更多
趁早两清
4楼-- · 2020-05-24 19:52

Try putting a + before R.xyz. That should start showing additional folders, e.g.:

+ R.raw.beep.mp3
查看更多
爷的心禁止访问
5楼-- · 2020-05-24 19:57

If you have a res/raw folder, be sure to add a file with a valid filename, otherwise the entire folder won't show up in the R class. If there's an error with a filename, it will appear in red in the console.

查看更多
Explosion°爆炸
6楼-- · 2020-05-24 20:00

Using IntelliJ Idea:

1) Invalidate Caches, and 2) right click on resources, New Resources directory, type = raw 3) build

note in step 2: I was concerned that simply adding a raw directory wouldn't be enough...

查看更多
一纸荒年 Trace。
7楼-- · 2020-05-24 20:02

The R class is written when you build the project in gradle. You should add the raw folder, then build the project. After that, the R class will be able to identify R.raw.*.

查看更多
登录 后发表回答