2.1.2.- PROCESOS DE LA FUNCIÓN GERENCIAL
2.2. AUSENTISMO LABORAL
2.2.1. CAUSAS DEL AUSENTISMO LABORAL
2.2.1.1. INTRÍNSECAS
We know a theme is a special style that is applied to an Activity or to an application instead of a single View. A theme is always a style and when we want to define a theme we use the same technique used before when defining a style, so we create a XML file under res/values. Android provides a large collection of themes and styles that we can use or override customizing them.
Let us suppose we want to create a theme for all the application that sets the background to green. In this scenario, we define a style called AllGreen in this way:
<style
name="AllGreen"
parent="@android:style/Theme.Black" >
<item name="android:background">#00FF00</item> </style>
and then we apply it to the application in the Manifest.xml: <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AllGreen" > </application>
As a result the Activity background is green as we wanted. We have defined before a style for TextView and now we would like to use it in our theme. To do it, we have to modify it a little bit:
<resources xmlns:android="http://schemas.android.com/apk/res/android" > <style
name="MyTextStyle"
parent="@android:style/Widget.Text<code>View</code>" > <item name="android:textColor">#FF0000</item>
<item name="android:textSize">14sp</item> </style>
<style
name="AllGreen"
parent="@android:style/Theme.Black" >
<item name="android:background">#00FF00</item>
<item name="android:textViewStyle">@style/MyTextStyle</item> </style>
</resources>
By now we used just solid color for the background and we have seen it is easy to change the background, but what if we want to use a gradient color?
In the previous chapter we described how to create a gradient: we have to create a file with XML extension under res/ drawabledirectory; we call it grandient_red.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient
android:endColor="#AA0000"
android:startColor="#FF0000"
android:type="linear" /> </shape>
Now we have to reference it in our style and for simplicity we can create another style file called style_gradient.xml: <resources xmlns:android="http://schemas.android.com/apk/res/android" >
<style
name="RedGrad"
parent="@android:style/Theme.Black" >
<item name="android:background">@drawable/gradient_red</item> </style>
</resources>
As you can notice, we referenced the drawable we created under the drawable directory, using @drawable/file_name. Running an app with this style we have:
Until now, whenever we defibed colors or font sizes, we used some hard coded values. Even if this is possible, it is not recom- mended for several reasons:
• If we want to change the color or a font size for example we have to look for these values in the style file.
• We would like to change the font size and colors according to the platform version for example or according to the screen dimensions.
So it is a good practice to move the color definition and/or the font size and so on to an external resources and reference them in the style.
So let us rewrite the text style we used before where this time we write the style in an XML file called style_text.xml: <resources>
<style name="MyTextStyle1" >
<item name="android:textColor">@color/red</item> <item name="android:textSize">@dimen/myTextSize</item> </style>
</resources>
In this style we referenced an external resource that sets the text color and the text size. In this case, we have to create two files: one that we can call colors.xml containing the color definition and another one containing the dimension called dimens. xml:
<resources>
<color name="red">#FF0000</color> </resources>
<resources>
<dimen name="myTextSize">14sp</dimen> </resources>
We now know that we can reference external resources using the @ symbol, but sometimes we want to reference a single style element not the whole style.
For example, we want to reference the current text color, but we do not know which one will be used by the OS. How can we do it? Well Android provides the ? symbol, which we can use to access a single element. For example we can suppose we want to set the text color value to one defined in Android OS:
<style name="TextRef" >
<item name="android:textColor">?android:attr/textColorLink</item> </style>
5.3.1
Themes and platforms
Android provides an interesting feature that is useful when we want to create an app for different devices that can run on different Android versions.
Until now we used just res/values and we created several files that represent styles, dimensions, colors and so on. Android can use different resources according to the platform version, so we could adapt, for example, our themes and styles to the platform version, or we can even create a different style with different colors depending on the platform.
We know that newer Android version introduced some new features, APIs and resources including styles and themes. We could use newer themes when our app runs on devices that have a new Android version. At the same time, we want to keep the compatibility towards older Android versions. Using platform dependent resources we can achieve this goal.
In order to create a resource set that is dependent on the platform version we have to create a directory under res called values-vxxwhere xx is the API level; for example if we want to create a resource set that is suitable for Android 3.0 (API level 11) or higher, we can create a directory called values-v11. Under this directory we create style and themes. If we notice when we use Eclipse as IDE it creates two themes by default, one under res/values:
<style name="AppBaseTheme" parent="android:Theme.Light"></style> and another one under res/values-v11:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"></style> As you can see, these two themee have the same name but inherit from different parents.
We can not only specify our theme according to the platform version but also according to the screen size. For example, if we want to apply our theme when the smallest screen size is at least 600dp, we can create a directory called values-sw600dp and create under it our style file. This style and theme will be applied only when the device smallest screen size is at least 600dp. This technique is useful when we want to provide different style/theme according to the screen size. We could, for example, have only one style/theme defined in res/values and provide different text size according to the screen size. In this case we can only create a file called dimens.xml.