Introduction to Android Resources (Resource)

Source: Internet
Author: User
Tags arrays resource

Android Apps (APP) resources are stored in the Res folder at the project level;

The types of resources include values (value), drawable, colors (color), layouts (layout), animations (animation), styles (style), menus (menu), XML files, and raw resources;

Also automatically creates an R-type file containing references to each resource in the project, location:app->build->source->r->debug;

Hello_world, resources as shown:

1. Simple values (value):

Simple values include: strings, colors (color), Dimensions (Dimens), styles (style), string arrays, or integer arrays;

Styles can be inherited, using parent tags, inheriting attributes;

2. Layout (layout)

The layout can be used to define the user interface for any visual component (including activity and fragment), and the filename is the resource identifier;

In activity, the layout uses Setcontentview padding (inflate) to enter the user interface;

Mainactivity, Code:

@Override
protected void onCreate (Bundle savedinstancestate) {  
    super.oncreate (savedinstancestate);  
    Setcontentview (R.layout.activity_main); Populate the user interface with the layout  

3. Menus (menu)

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

After the menu resource is defined in XML, the menu can be filled (inflate) into the application through the inflate method of the Menuinflator service;

The file name is the resource identifier;

Mainactivity, Code:

@Override Public
Boolean oncreateoptionsmenu (Menu menu) {  
          
    //inflate the menu; This adds items to the Action bar I F it is present.  
    Getmenuinflater (). Inflate (R.menu.main, menu); Fill the menu with the user interface return  
    true;  
}

4. drawable

Includes bitmap and ninepatch (PNG image can be stretched), can be used as an icon, should meet the requirements of various sizes;

DPI = Dots-per-inch;

When the remaining resources are used, explain them again.

Author: csdn Blog spike_king

Related Article

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.