Android resources are very essential for developing android related projects in Android Development platform. Actually, without knowing resources we cannot fulfill the requirements of the apps. This global technology is working throughout the world, so when we want to develop our system, we have to get all the information on the android platform with various resources. If the resources are not properly known, we cannot get the actual idea of the android system.
Without a brief definition about the android resource, we cannot get the actual data or actual applications working. In the Android resources level, we will be discussing about different components, which are not unreliable type of Android phrases. They are the first-class citizens in the Android platform. Resources can be classified in the following categories as mentioned below.
- Layouts: This is used for showing different layouts of the Android devices.
- Strings: It is also a part of the data type. We generally use this for showing the message in our devices.
- Images: This is part of the devices graphics area. It says what types of graphics are set.
- Dimensions: Different devices have different dimension but we have to maintain a standard dimension for our devices or project.
- Styles: Style is necessary in the android recourses because if we have no idea about the style of the system then we will not be able to develop the tools with proper information.
- Themes: We all know about the theme of various devices. We also know that theme is very essential for attractive look and feel. So the themes, Image, and Style are all inter related with each other.
- Values: This is used for the value present in the variable and takes the datatype of the variable. Basically we have the idea that two datatypes are present, one is called primitive data type and the other one is called non primitive data type. Here we will give a tabular format of the discussion of different data types that we use for our project development purpose.
- Menus: Menu is generating for accessing different types of data from the device.
- Colors: Color is another graphics part of the android resource system. Through this graphics process we can develop our system in a user friendly way.
We have to give a very fine idea of the following categories as per our requirement. We have already been introduced to the layouts, strings, and images in very little manner because they are the most common types of resources that we can utilize in our regular Android application development. Another resource may be a little complex for us, so we take a moment to clear up the idea.
Dimensions in Android Recourses
In an Android resource, a dimension is a number that is followed by a unit of measurement such as 10px (pixel), 2in (inch), or 5sp. We would use the dimensions at the time when we specify any other property which requires a numeric unit of measure. As per illustration we may want the padding of a layout to be 10px (pixel). In that program the following units of measure are supported by the Android resources, like in Table 1.
Table 1. Unit description table
Styles in Android Recourses
Styles in Android are very similar to the Cascading Style Sheets (CSS) in the Web development domain. A style is a collection of the properties that can be functional to any individual view in the layout file, activity, or our entire application within the manifest file. Style supports inheritance, so we can make available an identical basic style and then transform it for each individual use case we have in our application. As per Illustration we can say, style properties include font size, font color, and screen background.
Themes in Android Recourses
Theme is a style applied to an entire activity or submission, rather than just an individual view. When a style is applied as a theme, every view in the activity and/or application comes into those style settings. As per illustration, we can convert all the TextView views to be a particular font, and all the views in the themed activity or the presentation demonstrate their text in that font.
Values in Android Recourses
The standard android recourses consist of different types of value resources for our presentation. In
Table 2we can see the list of those resources.
Table 2. Datatype descritption
Menus in Android Recourses
It is true that menu is very important part of our android programming model architecture because through the menu concept users can easily get familiar with their devices. Menus can either be defined through code or through XML (Extensible Markup Language). The preferred way to express menus is through XML (Extensible Markup Language); therefore the innumerable menus that we construct should be placed into the menus/ directory. Respectively the menu has its own .xml file.
Colors in Android Recourses
The colors file is also positioned in the values/colors.xml file. This file give colors a forename such as login_screen_font_color, which is one type of systematic file name. This might represent the color of the font that we are using in the logon page. Individually the color is defined as a hexadecimal assessment.
To Work with Android Resources
Points should be remembered that we have worked with resources a small number of times in this article previously, and it is in all probability that we are aware to position the R class to add resources from within our submission. The R file should be generated carefully to make the application run smoothly.
To Move strings into the Android Resources
At the level of improvement, we have been acknowledged to take shortcuts to get the project build and function well. We will walk through the process, how to cut a string into a resource using the built-in tools.
The long way
The “long way” process is described below:
- Stepping to create a new string resource.
- Also copy its name in the system.
- Replace the string value in our layout with the resource identifier. This may not be a huge pain; nevertheless it takes time, possibly 30-45 seconds for the average developer or designer.
The fast way
We are also going to show how to cut that number under 15 (fifteen) seconds. Unfortunately we do this 30 (thirty) times a day which is feasible in an 8-hour day, we can also save 15 (fifteen) minutes of just copying and pasting work. That is five hours a month doing the copy and- paste jazz! Follow the steps below.
- If Eclipse is not open, we have to open it now and open the main.xml file in the layouts directory.
- After that we find the following chunk of program in the file
<Button android:id=”@+id/toggleButton” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center_horizontal” android:text=”Welcome to android recourses of SGC..” />
- After that we just select the boldface line “Welcome to android recourses of SGC”.
- Now we Press Shift+Alt+A from keyboard.
- After opening this, it opens a menu with three options.
- And we prefer the Extract Android String option from the above code.
We can now distinguish that the arrangement file has been made in order. The actual text “Welcome to android recourses of SGC..” has been substituted with “@string/ Welcome to android recourses of SGC”. If we want to unfasten the strings.xml file in the res/values folder, then we can distinguish a new file supplied with that name, and the value of the “Welcome to android recourses of SGC..”. Now we can understand that this process can save us a lot of time, instead of doing it 20 (twenty) to 30(thirty) times a day.
Wrestling the image beast in the Android Resources
This is one very interesting and difficult part of the Android Resources. Actually, the Images capacity gives the impression of being great on a medium-density piece of equipment, but the equivalent image strength on a high-density device looks like rubbish. It is the rule of the raster graphics. We have already discussed that in graphics there is a process where high quality pictures can be easily set with very well formation in the low quality device. If we are working with the low quality picture in the high-density image system then it is too much complicated. Nevertheless, if we are working on the platform of the vector graphics then those types of problem cannot occur. This is where the multiple density folders come into picture.
Battling pixilation and compression in Android ResourcesBattling and compression are very much reliable parts in the android development system. Nominal dots in the image is called pixel (px). The computer graphics is classified in two categories: the one category is called Vector graphics and other is called Raster graphics. Vector graphics is working with the concept of geometry of the mathematics as like two dimensions or three dimension formats. On the other hand, the raster graphics is the formation of the pixel concept. When we are trying to work our system with the graphics media then we must work with pixels.
As per illustration, if we are building our launcher icon (tiny image), build it at 250px (pixel) height and 250px (pixel) width. Although the hdpi (High dot per inch) folder might only need a 72px (pixel) -height-x-72px-width image (which is the largest used right now), it does not represent that in two to three months an Android tablet or Google TV would not come out. This can be excluded for the reason that working with large image files in image-editing programs can be difficult if we do not have a decent-performing computer. Having a large raw image file that is of high density is to a great extent easier to grow. Rationalizing a high-density image does not misrepresent the quality (other than bringing up the fine boundaries and the details of it), Nevertheless up scaling does for the reason that it creates the pixilation and the misrepresentation. Starting with a large file reduces the chances that we will ever have to upscale, with the resources that our app graphics will always look crunchy.
If we are creating our graphics in an image-editing tool that already supports layers, we highly give an opinion to place each item in our graphics on a different layer position. The reasons for this are numerous; nevertheless here are some key factors present:
To make our apps global with the android recourses
The Android platform exceeded Apple’s iPhone in United State. At present the world is developing more Android-based smartphones, which means one simple thing: more potential users for our android apps. So what does this mean to us as a developer? It means that Android is a huge market with tons of opening in the making of applications. This opportunity is very exciting, but to take the greatest advantage of it, we need to understand android recourses and in what way they affect the usability of our apps. As per illustration, if the user in the United States uses our app and our app is transcribed for an English audience by using resources or not, the user would be able to use it in a very well format. Though, if we are hard coding all of our string values into our views and activities and then need to release a Chinese version, we would have to rewrite our application from scratch. When we use resources we can have a proper way to transform our strings and variables into the region in which we are targeting such as China.
Resources allow us to make human-readable strings (String means data or message of the user), images (image means the photo, graph or any other media of android recourses), and viewable layouts into android resources that can be oriented. Innumerable android recourses folders can be created to handle various size of the screens, different languages (think strings and variables), and layout opportunities such as landscape or portrait (Actually these are the page orientation or our looking orientation). The Landscape and portrait views come into performance when a manipulator interchanges the 90 (ninety) degrees in either direction (left rotation or right rotation). If we want our apps to be viewable on as many Android devices as possible around the world, we want to use the resources all the time. As per illustration we advise that we always put all our strings into the strings.xml (this is the xml file) file because sooner or later, somebody from alternative region or country will want our application in another language. To get our presentation into another language, we simply need to have a linguist translate our strings.xml file into their respective language, and then we can create various folders to hold the applicable values region wise.
As per illustration, if the user is in China and their phone is set to the Chinese character set, Android looks for a principles folder called values-can, which is where Chinese values are stored including the Chinese version of the strings.xml file. Unfortunately, Android cannot find such folder because the platform defaults to the default value folder, which contains the English variety of the strings.xml file. When it comes into picture, we create a new folder with the new strings.xml file located in the folder structure.
We are no longer looking at mobile users as our target audiences. But we are looking at Android users which could be billions in number. Using the resources, we can do our development into foreign markets in an easy way. Designing our application for various regions is a big thing. We can also check in-depth material in the localization article of the Software Development Kit documentation from the android development site in localization.html file. Although designing our application for various regions sounds good and also compelling, it also helps to know that the Android Market allows us to understand which region our device is targeted for.
Actually the android recourses are very much essential for the Android application development. So this article is very much important for the Android developers. Here, we have discussed various types of android recourses, because it is true that android is not only used in few countries but it is used all over the world. We have also discussed a simple illustration for better understanding of the coding part. We have covered all the aspects of android resources and their usage. Hope the readers will get a concrete idea and they will be able to use it in their development.