Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load from string.xml resources files depending on gender in android

I am working on application where themes and strings differs when user is male or female. I could control colors depending on user gender but now i can't solve problem of strings for example if user is a male, I will use

<string name="welcome">Welcome boy</string>

but if user female it will be

<string name="welcome">Welcome girl</string>

that is just for example.so how can i load the correct file from resources depending on gender value which is stored in variable ??

like image 325
Sarah Sami Avatar asked Jul 29 '15 20:07

Sarah Sami


People also ask

In which folder can you find the string resource file strings XML?

The XML resource files containing localized strings are placed in subfolders of the project's res folder.

Why should you use string resources instead of hard coded strings in your apps?

It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).

What is the use of string XML file in Android?

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.


2 Answers

There's no direct support for what you are looking for in the plaform, so you need to write the logic yourself and have two strings per entry (i.e. welcome_m for males and welcome_f for females). But you need to set it on your widgets from code depending of who is using your app.

like image 78
Marcin Orlowski Avatar answered Sep 29 '22 13:09

Marcin Orlowski


Define array for gender-specific expressions, for example:

<string-array name="welcome">
    <item>Welcome Boy</item>
    <item>Welcome Girl</item>
</string-array>

Define for yourself the [0] item is male and [1] is female

like image 22
Amir Hossein Ghasemi Avatar answered Sep 29 '22 13:09

Amir Hossein Ghasemi