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 ??
The XML resource files containing localized strings are placed in subfolders of the project's res folder.
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).
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With