Android Learning: Resource Management

Source: Internet
Author: User

1: In a nutshell, Android resources refer to non-code parts, slices, MP3, strings, XML files, etc.


2: In an Android project, and the SRC source file has two folders, respectively called Res and assets, these two files are to save the resource file.
Different points:
(1) Res resources can be accessed through the R resource class. This method is more commonly used in Android.
Res contains subfolders that categorize resources:
Anim (XML animation file), drawable (image), layout (layouts file), menu (menus), raw (binary) values (constant value), XML (XML file)

(2) Assets in general is the original files, such as: MP3 files, Android programs can not directly through the R resource class access. Must be read in binary form through the Assertmanager class.


3:res Resource Acquisition Method
(1) In code: the Getresources () method of the context obtains the resources object, which provides a way to obtain various types of resource.
(2) References to resources in other resources
@[Package Name:] Resource type/resource name
R. Resource type. Resource Name

Configuring the background color in XML
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Tools:context= ". Mainactivity "
android:background= "@color/bg_color" >


<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/hello_world"
Android:textcolor= "@color/text_color"/>
</RelativeLayout>


Change background color in Java

This.getwindow (). Setbackgrounddrawableresource (R.color.bg_color);



Android Learning: Resource Management

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.