Android & ADT: project resources types

Trabla: Adroid Developer Tools project resources   explanation ( folder "res/values")

Solving:

In ADT project in folder  "res/values" we place .xml files with description of resources.
Name of file doesn't matters - e.g. "caramba.xml" is OK.

Mandatory content for .xml resource file:

<?xml version="1.0" encoding="utf-8"?>
<resources>

        <!--  Put resource tags here -->

</resources>


Resourses Types:
-----------------
1.Bool
-----------------
Tag in resource file
<bool name="my_true_bool">true</bool
----------
Use in layout  xml
android:adjustViewBounds="@bool/my_true_bool"
----------
Use in code -
Resources res = getResources(); 
boolean myBool= res.getBoolean( R.bool.my_true_bool );
-----------------
2. Color
-----------------
Tag in resource file
<color name="my_color">#ffB6FF00</color 
----------
Use in layout  xml
android:background="@color/my_color"
----------
Use in code -
Resources res = getResources(); 
int myColor = res.getColor( R.color.my_color );
-----------------
3. Dimenstion
-----------------
4.ID
-----------------
5.Integer
-----------------
6.Integer Array
-----------------
7. Typed Array
-----------------


We can place different  types of  resources in one  .xml resource  file, but best practice is to create separate file for one type.

Example: file "caramba.xml" in folder "res/values"

<?xml version="1.0" encoding="utf-8"?>
<resources>

        <!--  Put resource tags here -->
        
        <!-- My Bools-->
        <bool name="my_true_bool">true</bool>
        <bool name="my_false_bool">false</bool >

         <!-- My Colors -->
         <color name="my_color">#ffB6FF00</color >
        <color  name="my_second_color">#ffff0000</color  >

</resources>




No comments:

Post a Comment