String resourcestring

The string resource file is located in the RES /values directory, and the root element is the tag in which each string is defined using the
tag, followed by the name attribute for the tag to specify the name of the string. For example: my application

Note: The resource file name cannot be uppercase and must start with lowercase letters A-Z,0-9, or "_"

Use the getResources() method to get the resource manager in the Activity, and then use its get method to get the corresponding resource file, such as String String, with getString, and String array using getArray

  • In an XML file
<TextView
  android:id="@+id/textView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/app_name" />
Copy the code

Color resources

The color resource file is located in the res/values directory. The root element is the tag. In this element, the tag defines each color, and the tag sets the name attribute to specify the name of the color

Color value definition description:

Red, green, and blue are all represented by 0-f. #f00 #ARGB is represented by transparent and red, blue and green primary colors, where transparency, red, green and blue are represented by 0-F. For example, to represent translucent red, you can use #8f00 #RRGGBB, and use the values of red, green and blue primary colors to represent colors. Different from #RGB, red, green and blue are represented by 00-FF. If you want to represent blue, you can use # 0000FF #AARRGGBB to represent transparency and red, green and blue, where transparency, red, green and blue are represented by 00-FF. For example, to indicate a translucent green, use # 8800FF00, where #00 means completely transparent and ff means completely opaqueCopy the code
  • In the XML configuration
<resources>
	 <color name="blue">#ff0000</color>
</resources>
Copy the code
  • In JAVA code:
getResources().getColor(R.color.title);
Copy the code
  • Used in XML:
<TextView
  android:id="@+id/textView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/app_name"
  android:textColor="@color/blue"/>
Copy the code

Size of resources

Size resource is also a common resource for Android application development. It is usually used to set text size, component spacing and so on.

For better screen adaptation, use match_parent and WRap_content when specifying control and layout sizes, and avoid setting fixed values for the width and height of controls. However, in some cases, match_parent and wrap_content alone are not sufficient, and you must specify a fixed value for the width or height of the control.

Company Description:

Px(Pixels) : Each Px corresponds to a point on the screen. For example, a 320 x 480 screen has 320 pixels In the landscape and 480 pixels In (Inches) In the portrait: a standard unit of length. Every inch is equal to 2.54 centimeters. For example, to describe the size of the phone screen, it is often said that 3.2 inches, 4 inches, etc., refer to this unit. If the phone screen is 4 inches, it means that the length of the phone screen (viewable area) is 4*2.54 = 10.16 cm Pt(points, pounds) : Unit of physical screen length, 1/72A inch Dip or DP (set to individual pixels) : An abstract unit of basic screen density. On a display of 160 dots per inch, 1dip=1px -- but as the screen density changes, the dip PX conversion also changes Sp(proportional pixels) : deals primarily with font sizes, which can be scaled according to user font size preferences. Millimeters: The physical unit of length of a screenCopy the code

Since mobile phone resolutions vary, a 200px wide button can take up nearly all of the screen on a low resolution phone and only half of the screen on a high resolution phone. Google, of course, is aware of this headache and has introduced a new set of units dp and SP for Android

Dp is the density and pixel independent, also known as DIP, compared to PX, it will display the same proportion in different densities of the screen sp is scalable pixel, it adopts the same design concept as DP, to solve the problem of text size adaptationCopy the code
Density in Android is the number of pixels per inch of the screen, usually measured in dPI. For example, a mobile phone screen that is 2 inches wide and 3 inches long has a density of 160dpi if it has a resolution of 320 × 480 pixels, and 320dpi if it has a resolution of 640 × 960. Therefore, the higher the density, the more detailed the screen will be.Copy the code

Layout resources

One of the most commonly used resources in Android is a layout file that can contain other layout files. The syntax is:

The < include layout = "@ layout/XXX" / >Copy the code

An array of resources

  • The array resource file is located in the res/values directory, and the root element is the tag, which contains the following three child elements
<array/> is used to define an ordinary array. <integer-array/> is used to define an integer array. <string-array/> is used to define an array of stringsCopy the code
  • Defining array resources
<string-array name="items"> <item> Program </item> <item> Mobile phone </item> <item> Call </item> </string-array>Copy the code
  • Using array resources
String [] arr=getResources().getStringArray(R.array.items); The android: entries = "@ array/items"Copy the code

Drawable resources

Description: Drawable resources are usually stored in the res/ Drawable directory. In fact, they are stored in the res/ Drawable - hdPI,res/ Drawable -ldpi,res/ Drawable -mdpi,/res/ Drawable - XHDP directory. High - resolution, low - resolution, medium - resolution, and ultra - resolution images are used in the ActivityCopy the code

Common state attributes are as follows

Android:state_checked Indicates whether the state is checked. The value is true or false. Android:state_enabled indicates whether the state is available. Android:state_focused Android:state_pressed Android:state_pressed Android:state_pressed Property value: true/false Android:state_selected Indicates whether the state is selected. The property value is true/falseCopy the code
Android :drawable="@color/red" drawable="@color/red"Copy the code

ShapeDrawable resources

The Shape resource draws a specific shape, such as a rectangle, ellipse, etc. If you want to draw binary graphics dynamically yourself, then we can use ShapeDrawable resource objects. With ShapeDrawable, we can draw any shape we can imagine. A ShapeDrawable requires a Shape object to manage rendering resources to the UI Screen. If no Shape is set, RectShape is used by default.

ShapeDrawable is defined in an XML file, starting with a

element. Each Drawable resource inside it is embedded in the

element

<? The XML version = "1.0" encoding = "utf-8"? > <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <! <gradient Android :startColor="#00f" Android :endColor="# 00F "Android: Angle ="45" Android :type="sweep"/> <! <padding android:left="7dp" Android :top=" 7DP "Android :right=" 7DP" Android :bottom=" 7DP "/> <corners Android :radius="8dp" /> </shape>Copy the code

Draw9-patch

  • The dot 9 image is a special format used in Android development. The file name ends with “.9.png “. This picture tells the program which parts of the image can be pulled up and which parts can’t be pulled up and you need to keep the same ratio. Using the dot 9 diagram can ensure that the image can be adaptive without fuzzy deformation.
Usage:

The top and left sections define the stretchable parts of the image, while the right and bottom sections define the content areas of the image.

Share with you

I want to work my way up

Fly forward on the blades at the highest point

Let the wind blow dry tears and sweat

I want to work my way up

Waiting for the sun to watch its face

Little days have big dreams

I have my day

Let the wind blow dry tears and sweat

One day I will have my day