Android IMP Data: Color Resources
Android IMP Data: Color Resources
Color Resources:
You can define XML files that contain definitions for colors that can be used in your application.
Colors in Android are hexadecimal RGB values, also optionally specifying an alpha channel (transparency).
You have your choice of single-character hex values or double-character hex values, leaving
<color name="Red">#FF0000</color>
TextView txtColor=(TextView)findViewById(R.id.txtColor);
txtColor.setTextColor(this.getResources().getColor(R.color.Red));
Dimensions Resources:
You can define Dimension resources to use them with your widgets to define padding, width or height.
Pixels: (px).
Inches: (in).
Millimeters: (mm).
Points: (pt).
Density: (dp) density-independent pixels based on 160 dpi (dot per inch).
Scale: (sp) Scale-independent pixels (dimensions that allow for user sizing; helpful for use in fonts).
To define dimension resources in xml files you can write it like this:
<dimen name="PixelDim">10px</dimen>
<dimen name="PointsDim">10pt</dimen>
<dimen name="InchesDim">0.2in</dimen>
<dimen name="MilliDim">5mm</dimen>
<dimen name="DensityDim">20dp</dimen>
<dimen name="ScaleDim">20sp</dimen>
And you can use them from the xml layout definition like this:
<textview android:id="@+id/txtInches" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Font size is 0.2 Inches"
android:textsize="@dimen/InchesDim"></textview>
Array Resources:
Array resources allow you to define custom string arrays that hold values you can use in your application such as a
countries list or a list of names.
An Array resource is defined using string-array element while items are defined using item element.
<string-array name="countries">
<item>USA</item>
<item>UK</item>
<item>Canada</item>
</string-array>
Image Resources:
Android provides us with the ability to use image resources in our
applications. We can put image files in res/drawable directory and access them
from the xml layout or by the generated ID from R.java class file.
ImageView img=(ImageView)findViewById(R.id.img);
img.setImageResource(R.drawable.android);