Android: How to add R.raw to project?

后端 未结 13 1410
半阙折子戏
半阙折子戏 2021-02-04 23:39

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.

相关标签:
13条回答
  • 2021-02-05 00:03

    Create a raw android resource directory.

    Once the raw directory is created, Make sure to add a valid media file

    1. Make sure to follow proper naming conventions (lower case letters with underscore '_' as separators)
    2. Media file should have a proper encoding and formatted media file in one of the supported formats.

    After following the above procedure, you should be able to access your media files by using R.raw.media_file

    0 讨论(0)
  • 2021-02-05 00:05

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

    0 讨论(0)
  • 2021-02-05 00:05

    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.*.

    0 讨论(0)
  • 2021-02-05 00:07
    • 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.

    0 讨论(0)
  • 2021-02-05 00:09

    (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.

    0 讨论(0)
  • 2021-02-05 00:10

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

    android.resource://" + getPackageName() + "/" + R.raw.filename
    
    0 讨论(0)
提交回复
热议问题