Tutorial by Examples

Strings can be internationalised by defining a different strings.xml for each language you support. You add a new language by creating a new values directory with the ISO language code as a suffix. For example, when adding a German set your structure might look like follows: When the system look...
Strings are typically stored in the resource file strings.xml. They are defined using a <string> XML element. The purpose of strings.xml is to allow internationalisation. You can define a strings.xml for each language iso code. Thus when the system looks for the string 'app_name' it first che...
In order to define a string array write in a resources file res/values/filename.xml <string-array name="string_array_name"> <item>text_string</item> <item>@string/string_id</item> </string-array> for example res/values/arrays.xml <?x...
Dimensions are typically stored in a resource file names dimens.xml. They are defined using a <dimen> element. res/values/dimens.xml <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="small_padding">5dp</dimen> &l...
Integers are typically stored in a resource file named integers.xml, but the file name can be chosen arbitrarily. Each integer is defined by using an <integer> element, as shown in the following file: res/values/integers.xml <?xml version="1.0" encoding="utf-8"?> &...
In order to define an integer array write in a resources file res/values/filename.xml <integer-array name="integer_array_name"> <item>integer_value</item> <item>@integer/integer_id</item> </integer-array> for example res/values/arrays.xm...
Colors are usually stored in a resource file named colors.xml in the /res/values/ folder. They are defined by <color> elements: <?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#3F51B5</color> <c...
Using the Android API 23 or higher, very often such situation can be seen: This situation is caused by the structural change of the Android API regarding getting the resources. Now the function: public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException should...
Define a menu in res/menu <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/first_...
Defining Strings in the strings.xml file also allows for string formatting. The only caveat is that the String will need to be dealt with in code like below, versus simply attaching it to a layout. <string name="welcome_trainer">Hello Pokémon Trainer, %1$s! You have caught %2$d Poké...
Color state lists can be used as colors, but will change depending on the state of the view they are used for. To define one, create a resource file in res/color/foo.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/ap...
To differentiate between plural and singular strings, you can define a plural in your strings.xml file and list the different quantities, as shown in the example below: <?xml version="1.0" encoding="utf-8"?> <resources> <plurals name="hello_people&quo...
There are cases, where custom objects need to be created and defined in the resources of the application. Such objects can be composed of Java simple types, for example Integer, Float, String. Here is the example of how to import an object defined in application resources. The object Category cons...
9 Patches are stretchable images in which the areas which can be stretched are defined by black markers on a transparent border. There is a great tutorial here. Despite being so old, it's still so valuable and it helped many of us to deeply understand the 9 patch gear. Unfortunately, recently tha...
Hex Opacity Values ------------------------------ | Alpha(%) | Hex Value | ------------------------------ | 100% | FF | | 95% | F2 | | 90% | E6 | | 85% | D9 | | 80% | ...
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String XML resource that provides a single string. Syntax: <?xml version="1.0" encoding="...

Page 1 of 1