Android resource alias

Source: Internet
Author: User

When you want to develop multiple devices for android, you need to prepare resources under multiple configurations. Of course, you also need to provide the default source. if the resources under multiple configurations are the same, you can copy the same resources to the corresponding directory. However, this is not a good practice. In fact, we can use the resource alias.

However, this method is not applicable to resources in the animation, menu, raw, and xml directories.

For icon.png images, res/drawable-en-rCA/and res/drawable-fr-rCA/configurations, the icon.png images are the same. in this case, you can change icon.png to a name such as icon_alais.png under the res/drawable directory, and then reference it in res/drawable-en-rCA/, res/drawable-fr-rCA/examples. in the generated R class, we use R. drawable. icon variable for Reference

Drawable
Use <bitmap> element to reference resources
Xml Code
<? Xml version = "1.0" encoding = "UTF-8"?> <Bitmap xmlns: android = "http://schemas.android.com/apk/res/android" android: src = "@ drawable/icon_ca"/>


Layout
Use the <include> and <merge> Elements
Xml Code
<? Xml version = "1.0" encoding = "UTF-8"?> <Merge> <include layout = "@ layout/main_ltr"/> </merge>


Strings and other simple values
Use resource id as reference
Xml Code
<? Xml version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "hello"> Hello </string> <string name = "hi"> @ string/hello </string> </resources>


Xml Code
<? Xml version = "1.0" encoding = "UTF-8"?> <Resources> <color name = "yellow"> # f00 </color> <color name = "highlight"> @ color/red </color> </resources>

This article is from wen66"
 

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.