Color Resources
The definition of a color value is defined by an RGB primary color and an alpha value. The beginning of a color value definition is a
The pound sign (sentence, followed by the alpha-red-green-blue format. For example:
#RGB
#ARGB
#RRGGBB
#AARRGGBB
Color resources are located under the Value folder, create a new. xml file, add code inside it
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<color name= "Hong" > #ff0000 </color>
<color name= "Huang" > #00ff00 </color>
<color name= "LV" > #0000ff </color>
</resources>
To reference a color resource in a resource file:
<textview android:id= "@+id/text1" android:layout_width= "match_parent" android:layout_height= "wrap_content "Android:text=" @string/str1 "android:textcolor=" @color/huang "/>
Add the code as above in the layout file, the reference format is "@ Color resource filename/color_name" (@color/huang)
In. Java code, reference the color resource, add the following code in. java
public class Mainactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) {Super . OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); This.getwindow (). Setbackgrounddrawableresource (r.color.lv); Set background color//use R.color.color_name (R.COLOR,LV) to refer to//...}
string Resource
String resource is located under the Value folder, create a new. xml file, add code inside it
<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >helloabc</string > <string name= "hello_world" >hello world!</string> <string name= "Action_settings" >Settings< /string><string name= "str1" >hello android!! </string></resources>
To reference a string resource in a resource file:
<textview android:id= "@+id/text1" android:layout_width= "match_parent" android:layout_height= "wrap_content "Android:text=" @string/str1 "<!--str1 as defined string resource--android:textcolor=" @color/huang "/>
referencing string resources in. Java:
Using functions
GetString (R.string.string_name). toString ();
eg
String string = GetString (R.STRING.STR1). toString ();
Bitmap Resource
drawable resources are pictures or color resources that are used primarily to draw screens through Resources.get
The Drawable () method is obtained. drawable resources are divided into three categories: Bitmap File (bitmap), Color drawable
(color), Nine-patch image (nine pictures). The use of commonly used bitmap files is only described here.
The bitmap files supported in Android are PNG, JPG, and GIF.
Copy the picture to the res/drawable file, refresh the project, update the item automatically, and get the bitmap ID, as you can see in R.java drawable.
Ps: The name of the picture can only be a-z1-9.png, cannot appear larger letters
To reference a bitmap in a layout file:
<imageview android:id= "@+id/pic1" android:layout_width= "wrap_content" android:layout_height= "wrap_content "Android:src=" @drawable/prenren "/>
As in the code, refer to the picture source in android:src format "@drawable/picture_name" ("@drawable/prenren")
To refer to a bitmap as an icon in a menu file:
<item android:title= "Edit"
android:icon= "@drawable/prenren"
</item>
In Java code, you can reference it in the following ways:
ImageView Myimageview = (ImageView) Findviewbyid (R.ID.IMAGEVIEW1); Resources r=getresources ();//drawable Instance drawable d=r.getdrawable (r.drawable.picture_name) obtained through resources;//settings The Imagedrawable property of the ImageView displays the picture maimageview.setimagedrawable (d);
can also be combined to write:
This.getresources (). getdrawable (R.drawable.prenren);
This article is from the "Useless Uncle" blog, please be sure to keep this source http://aslonely.blog.51cto.com/6552465/1614844
Android Resource Details (i) color, string, bitmap resources