Android Tutorial For Beginer - Qualify Resources Examples

Here we have a few examples of how easy it is to use qualifiers to designate specific resources for specific configurations. In the first example we want to define different graphics or drawable resources based on the screen resolution of a device. In Android the screen resolution is usually defined in reference to DPI or dots per inch. Lets take the example of developing an application that has default drawables, which our are graphical resources like png images, and higher resultion drawables for higher resolution devices. We can store our default drawables in the drawable folder in our resources directory and store the higher resolution assets in the drawable dash hdpi folder of our resources directory. In runtime Android will use the resource based on the screen resolution configuration of the device When implementing multiple languages we will use a similar naming convention to create different values folders. The values folder can contain resources for our string constants, arrays, colors, predefined dimensions and styles and themes for the application. By adding a qualifier to the end of the values folder name we can define values to be used for different locals. For instance to implement multiple languages for our application we can create a values folder a values dash es folder and a values dash fr folder in our resources directory. In the values folder we would add a strings.xml file containing strings for our default language which in most cases would be English, in our values dash es folder we would add a strings.xml file containing string constants in Spanish, and in our values dash fr folder we would add strings.xml file containing our strings constants in French. Then when the application is run on a device with a Spanish locale or a French locale it would use those string constants accordingly, or otherwise use the default string constants in our values slash strings.xml file. Just that easily we can define resources to be used for specific locales, screen types, or even orientations.
0 Komentar untuk "Android Tutorial For Beginer - Qualify Resources Examples"
Back To Top