Application resources available in Xamarin. Android
12 minute(s) read
|
Published on: Mar 24, 2021
Updated on: Dec 14, 2021
|
After sending the user request to launch the application, it refers to the resources available on the operating system to launch and launch the application. Applications have user interface layouts that exist in XML files.
Applications available on the Android OS have resources that we will teach you in this tutorial.
Basics of app assists in Xamarin-Android
When an application is created for the Android operating system, the assists related to that application are set by the default Xamarin.Android template.
The files that create the default assists are as follows:
icon:
This file has the default Icon.png for the application icon created.
Main.axml:
This file has the default user interface layout for the created application.
Note:
Android supports the xml format while Xamarin-Android uses the axml format.
Strings.xml:
Creates a string table that is used to help localize Word applications.
AboutResources.txt:
This file is unnecessary, and you can even delete it because it does nothing special. It just provides an overview of the level of assists files.
Resource.designer.cs:
Unlike the AboutResources.txt file, this file is very important and is produced by Xamarin.Android. This file has unique IDs for each source. This file was created automatically by Xamarin-Android and restored from time to time if needed.
How to create and access them?
Creating application assists is a very simple and easy task. Add Strings.xml to the file and project. Once added, Build Action is automatically set to AndroidResource. Xamarin does AndroidResource setting.Android tool. Doing so will allow you to properly compile the Xamarin. Android tool and embed the assists into the APK file.
Note:
If Build Action is not set up properly on Android Resource, all existing files in the APK will be removed, and no attempt to set or upload files will be effective. In this case, you will encounter a runtime error, and eventually, the application will crash.
Unlike Android, Xamarin. Android is not strict and supports all lowercase and uppercase characters. And you can easily use uppercase or lowercase letters when naming them because of Xamarin. Android does not give any error for using uppercase and lowercase letters.
Note:
When naming sources to separate if you use dashes or spaces are not supported and processed. You can use the underline to separate them.
How to access this added to the file?
There are two ways to use the added to the file:
- Use XML files
- Coding to access resources
Access to added assists through coding
To access the available assistance by programming method, we must assign each resource a valid and unique identifier. The unique identifier assigned to each resource is an integer defined within the Resource class.
The code inside the resource.designer.cs file gives access to the resources, the code inside the resource.designer.cs file must be as follows to be able to access the added resources:
By entering this code, you assign a valid identifier to each resource, although the identifiers assigned to the resource are related to the resource type. For example, when Icon.png was added to the project, the Resource class was updated by Xamarin.Android.
Resource should not be changed manually, as Xamarin will replace all its changes. Android.
To access the created using the coding method, you can also use the code below:
PackageName:
A package whose job is to provide a resource.
ResourceType:
A type of resource that is distributed as described within the Resource class.
Resource Name:
Is the source's name that the source name must be without extension.
Access added resources via XML file.
The inside the XML file is as follows:
PackageName:
A package whose job is to provide a resource.
ResourceType:
A type of resource that is distributed as described within the Resource class.
Resource Name:
Is the source's name that the source name must be without extension.
The code inside the Main. axml file to access this via the XML file is as follows:
Check the contents of the Main. axml files are not the same as the code below. Replace the code below with the contents of the Main. axml file.
In this code, ImageView sets the src property to @drawable / flag.
Learn how to set the default of apps in Xamarin.Android
Default resources are resources that are not specific to devices and applications. There are specific assists for each application or device selected by default if the Android operating system does not find specific resources. Default assists exist from the beginning, and if device-specific resources do not run, default resources will run instead of specific resources.
The different types of sources are as follows:
Animator:
XML files are used to describe property animations. Property animations for version 3.0 of Android were introduced and launched. Property animations are flexible and are a powerful way to produce different types of animations that are used.
Anim:
XML files are used to describe tween animations. Tween animations are a set of animation commands used to make changes to the contents of the View object. For example, rotating and moving images or resizing text in animation uses Tween animations to change View objects.
color:
XML files that are used to describe a list of colors. Consider an example of changing the color or using the colors in the list, changing the button mode, and changing its color. A button can have active or inactive modes, or compressed or non-compressed modes, in which case the color of the button will change as well.
Drawable resource:
In general, it can be said that drawable is a concept used for graphics. Anything related to graphics in the program can be drawable inside. The drawable can be easily compiled within the program, then called by the API, or referenced using other XML resources. Bitmaps (.png, .gif, .jpg) are examples of drawable that can also be resized. Such as state lists and Nine-Patches ...
Layout:
XML files used to describe the interface layout, such as an activity or a row in a list.
menu:
XML files used to describe program menus such as Context Menu, Options Menu, and submenus. Popup Menu Demo and Standard Controls are examples of in-app menus.
Raw:
These are files that are automatically saved in binary type in raw.
values:
Are XML files that have simple values. An XML file in the values directory does not define a single source but several sources.
xml:
Are XML files that function similarly to the .NET configuration.
Learn how to set up alternative sources for apps on Xamarin.Android
Alternate resources are resources used by the Android operating system in the absence of default resources. If Android is looking for a default source but finds a more accurate source than the default one, it will select and run a more accurate source. Of course, if Android does not find an alternative source that is more accurate than the default source, the same default source will be downloaded.
Alternative resources are placed within resource files, such as the default resources, as subcategories of the default resources:
Qualifier:
A name is used to identify the device configuration. There may be more than one qualifier with one name, in which case a hyphen separates the names.
The rules that must be followed when adding Qualifiers to the are as follows:
- There may be more than one qualifier with a name, each of which is separated by a dash.
- The qualifier may be specified only once.
The different types of qualifiers that are mentioned for its as follows:
MNC and MCC:
MCC is used to provide and configure the SIM card, while MNC provides the device connected to the network. The values in MNC and MCC are different for other countries and sources. For example, when assigning a qualifier to a country in Germany, the qualifier must be mcc262. When assigning a qualifier to the United States, the qualifier must be mcc310-mnc026. For information on country codes, you can visit http://mcclist.com/.
Smallest Width:
It specifies the smallest width of the page intended to run the application.
Available Width:
The minimum width of the page intended to display the application and the value can be changed by rotating the device.
Available Height:
The minimum height of the screen that is intended to display the application and the amount of this can be changed by rotating the device.
Screen Aspect:
This qualifier is based on the screen's dimensions, not on the orientation, and does not change with the rotation of the device. The values included in this qualifier are not long and long.
Screen Orientation:
This qualifier can be changed by rotating the device, and the values placed in it can be landscape or Portrait.
Dock Mode:
It is a qualifier that can take car or desk values.
Night Mode:
This qualifier is used to determine whether the program is used during the day or at night. This qualifier allows users to use dark or light modes of user interfaces. The values in this qualifier are not night and night.
Screen Pixel Density:
They are used to specify the number of pixels at a point on the screen.
The values in this qualifier are as follows:
ldpi:
Screen with low density and number of pixels
mdpi:
Screen with medium density and number of pixels
hdpi:
Screen with high density and number of pixels
xhdpi:
Screen with very high density and number of pixels
nodpi:
Resources that have no value
Touchscreen Type:
Used to determine the screen's touch and the values in this qualifier can be no-touch, stylus and finger. The finger is used to specify the touch screen, the stylus is used to define the screen using the stylus, and the no-touch is used to specify the non-touch screens.
Keyboard Availability:
Used to determine the type of keyboard used, and its values may change by changing different types of keyboards. The values that this qualifier can take are as follows:
Keys exposed:
In this case, the device has an available and active keyboard, and if there is no software keyboard, the hardware keyboard will be launched.
keyshidden:
In this case, the device has a hardware keyboard, but the hardware keyboard of this device is hidden, and of course, no software keyboard is active.
keyssoft:
In this case, the device has a software keyboard.
Primary Text Input Method:
This qualifier is used to specify what kind of hardware keys are used for input. The values in this qualifier are as follows:
nokeys:
There are no hardware keys to log in to the app.
Qwerty:
There is a qwerty keyboard.
12key:
There is a hardware keyboard that has 12 hardware keys to enter.
Navigation Key Availability:
Activated when there are five directions and of course, the values in this qualifier are as follows:
nav exposed:
Navigation and directional keys are active for users to use.
Navhidden:
Navigation keys are disabled for use by users.
How does Android determine which source to use?
In the Android OS, the produced applications have a lot of resources, and for the applications to be launched, they must be run on a source. The number of resources available in Android is high, and the question is how the Android operating system determines which source to use.
Android determines the resources bases as follows:
Eliminate contradictory qualifiers:
In this case, if the device orientation is Portrait, all directories in the landscape source will be rejected.
Ignore qualifiers not supported:
Not all qualifiers are available for all API levels. If the resource directory has a qualifier not supported by the device, that resource directory will be ignored.
Identify the next highest priority qualifier:
Selects the highest qualifier priority based on the table. Qualifier priority is from top to bottom.
If the Android operating system is looking for specific resources and cannot find them, it will find other resources. In this case, the Android operating system may not use the default resources. For example, if the operating system is looking for low-density pixel resources and cannot find them, it chooses medium or high-density pixel resources.
Imagine an app whose are as follows:
All resources that do not comply with the en-GB language will be removed.
This application is run with these on a device with the following features and facilities:
After deleting resources that do not comply with the en-GB language, the available resources are as follows:
Then, French sources that do not conform to en-GB are removed as follows:
Orientation is then performed, and all directories that do not match the page orientation are removed:
In this way, the
Android operating system
selects the appropriate source to use.
About our Android and iOS app development services