Android development —— 8, resource access

(1) String resource file: located in the res\values ​​directory, the root element is <resources></resources>, and each string is defined using the <string></string> tag in this element.


(2) Color resources:

Four forms:

  • #RGB: Use the values ​​of the three primary colors of red, green, and blue to represent colors, where red, green, and blue are all represented by 0~f.
  • #ARGB: Use transparency + red, green and blue to represent colors
  • #RRGGBB: 00~ff to indicate
  • #AARRGGBB: Use red, green and blue with opacity +00~ff to represent

(3) Layout resources

Layout resources are located in the res\layout directory

Specify the layout resource used in MainActivity:

setContentView(R.layout.linearlayout);

(4) Array resources are
located in the res\values ​​directory. The root element is the <resources></resources> tag, which includes the following three sub-elements:

<array> child element: used to define an array of common types.
<integer-array> child element: used to define an integer array
<string-array> child element: used to define an array of strings

Use array resources: For example , to obtain a string array named listItem
in MainActivity.java , you can use the following code String arr[]=getResources().getStringArrar(R.array.listItem); another example:

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@array/ctype"> //Use the contents of the array string array to display
</Spinner>

(5) The image resources are
located in the res\drawable directory:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325733317&siteId=291194637