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条回答
The star\"
2楼-- · 2020-05-24 19:37

Adding a raw folder to your resource folder (/res/) should do the trick.

Read more here: https://developer.android.com/guide/topics/resources/providing-resources.html

查看更多
成全新的幸福
3楼-- · 2020-05-24 19:37

Here is the string to access files in raw folder. Replace filename with name of your file.

android.resource://" + getPackageName() + "/" + R.raw.filename

查看更多
神经病院院长
4楼-- · 2020-05-24 19:38

enter image description hereRight click on package or Res folder click on new on popup then click on android resource directory

a new window will be appear change the resource type to raw and hit OK copy and past song to raw folder remember don't drag and drop song file to raw folder and song spell should be in lower case! This method is for Android Studio Also Check MY Link

查看更多
兄弟一词,经得起流年.
5楼-- · 2020-05-24 19:39

To get it to recognize the raw file, make sure you create it, and add it as a raw resource file. Then go to build.gradle file and add this block of code.

sourceSets {
    main {

        assets.srcDirs = ['/res/raw']

    }
}
查看更多
Animai°情兽
6楼-- · 2020-05-24 19:40

(With reference to Android Studio)

Create a new directory in res folder. Make sure to create new "Android Resource Directory" and not new "Directory".

Then ensure that there is at least one valid file in it. It should show up now.

查看更多
SAY GOODBYE
7楼-- · 2020-05-24 19:42

Simply add a folder 'raw' to your res folder.

查看更多
登录 后发表回答