Xamarin.android How to use files in the assets directory

Source: Internet
Author: User

Personal original, reproduced annotated Source: http://blog.csdn.net/supluo/article/details/43672411

Xamarin.android official website address: Http://developer.xamarin.com/guides/android/application_fundamentals/resources_in_ android/part_6_-_using_android_assets/


Here, insert the similarities and differences between the assets and the raw directory.

The same points for both directories:

1. The files in these two directories will be stored in the APK package intact after packaging, and will not be compiled into binary files.

2. The files in both directories are read-only.

Different points:

      the files in the 1.res/raw are mapped to the R.java file, and the files under the R.id.filename;assets folder are not mapped to R.java when accessed, and Assetmanager classes are required for access.

2.res/raw can not have a directory structure, and assets can have a directory structure, that is, assets directory can be re-established folder

Assets allows us to include arbitrary text, XML, music, video and other files in the program, which is like providing some resources for the program to use. Changing the program font will place some pre-set font files in this directory.

Xamarin.android How to open a file in assets

1. The Set file generation operation is Androidasset. (to the right of the file, select Properties in the pop-up menu, you can see the Build Method column).

as some developers Use the Hack tool, and the version is low , so the newly added file may not be this way , so it's important to note that this could be a very tormenting problem. The way in which files are generated by copying from other places may not be the way they were generated.

2, used in the code, if the assets directory is now saved a file named "Read_asset.text"

    var TV = new TextView (this);    Read the contents of our asset    string content;    using (StreamReader sr = new StreamReader (Assets.open ("Read_asset.txt")))    {        content = Sr. ReadToEnd ();    }    Set Textview.text to our asset content    TV. Text = content;    Setcontentview (TV);


The code above can read the contents of the text in the form of a stream, and the second parameter of Assets.open can specify how the data is retrieved.


Personal made a blog app, usually a toilet, before bedtime and so casually read two articles, always have some harvest, I hope you support! http://blog.csdn.net/supluo/article/details/43489475

Xamarin.android How to use files in the assets directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.