Pluralization in Android

If you are writing an app, that uses a string containing numbers, for example: Deleted 1 message Deleted 2 messages You could manually create two different strings, and show either one by using an if/else, depending on the number variable. However, as you start internationalizing your app, by adding more translations, this quickly gets out of hand! Using Plurals Luckily, theres a great solution for this. In Android, you can use something called "plurals". You can use plurals in

» Read more

Android string.xml resource formatting

If you are using the strings.xml file for your applications string resources (which you should!) then you might have wondered what to do if you need to combine a string and a value. Take this text for example: Hi, my name is Ruben and I am 26 years old String resource formatting This can easily be solved by using string formatting to insert the values; Ruben and 26. In you strings.xml file, create a new string resource like

» Read more

Got a problem with spaces in strings.xml getting stripped away?

If you have a string in your strings.xml file that you want to have a space character in front or after the string itself, you may notice that this space gets trimmed away automatically. To avoid the string getting trimmed away, you can use one of the following tricks: Trick one – Wrapping the string in quotes If you wrap the string in a pair of quotes, the space will not get stripped away. Also, the quotes themselves does not

» Read more

How to extract strings into strings.xml resource files in Android Studio

I have previously posted a guide on how to extract string resources in Eclipse, so I thought I would do it for Android Studio too, as it is not directly obvious how to acheive this. All your applications strings should be placed in the various /values/strings.xml files in your app. This is the best practice, gathers all texts, and easily enables you to translate your app into other languages. While developing apps, it might be easier to just

» Read more

How to easily extract strings from your Android code into the strings.xml file

This handy little feature can save a lot of time and manual work when working with Android apps. If you during Android development in Eclipse use hardcoded strings in your java code, like in the example below: package test.layout; import android.app.Activity; import android.os.Bundle; import android.widget.Button; public class LayoutTest extends Activity { private Button btn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn = (Button) findViewById(R.id.Button01); btn.

» Read more