strings.xml conflict in Android Manifest - android

I have this in Android Manifest:
<application
android:label="#string/app_name"
...
</application>
and in strings.xml:
<string name="app_name">My App Name</string>
Everything ok. Now, my problem is that I'm using an aar dependency whose strings.xml file contains an item named app_name, too.
<string name="app_name">My Library Name</string>
And my project is using the second one instead.
How can I solve this conflict?

A unique resource name for the element, which you can use to obtain a
reference to the View from your application.
For better way , Just use Different String Name .

**Its very easy change key value app_name as per your way**
example
change strings.xml
<string name="app_name">My App Name</string> line like
<string name="my_app_name">My App Name</string>
Then in manifest file use
<application
android:label="#string/my_app_name"
...
</application>

Related

Lint does not check missing translations

I use Lint to check for missing translations in strings.xml (in values-de, values-en, values-hu, etc.). However, I noticed that if there are no strings in another language in other strings.xml files, Lint does not find the missing translations.
Example:
values/strings.xml:
<string name="abc">test</string>
values-en/strings.xml:
<!--empty-->
-> not work
values/strings.xml:
<string name="dummy">dummy</string>
<string name="abc">test</string>
values-en/strings.xml:
<string name="dummy">dummy</string>
-> works
Is there any way to force Lint to control that translation for string called "abc" is missing without adding dummy string? Unfortunately, even empty strings.xml files are not enough.
If you want to have a string only in strings.xml try that.
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation">
<string translatable="false" name="abc">test</string>
</resources>

Change the name of the application Android Studio

Hello I have a problem in calling the name of the application
I need to invoke the application of MainActivity name <String xxx>
<resources>
<string name="app">#layout/activity_main/#xxx</string>
</resources>
Is this possible
I do not want to use
<string name="app">name</string>
You got it wrong. It is actually the opposite way.
In strings.xml you declare:
<string name="app">Application name</string>
An in the activity you read:
getString(R.string.app);

How to include a Android values strings.xml file into another strings.xml

I need to put all codes inside values-zh/strings.xml into values-zh-rCN/strings.xml. How do i do this?
I've tried this <include layout="#values-zh/strings" /> but did not work, Intelij is telling me to declare the file first.
Assuming values-zh/strings.xml is your base string resources, you can put all your strings there, and only provide values for those you need to override in values-zh-rCN/strings.xml.
In values-zh/strings.xml:
<string name="title">default title</string>
<string name="content">default content</string>
In values-zh-rCN/strings.xml:
<string name="title">simplified title</string>
Now when you are on simplified Chinese config, content will be 'default content', and title will be 'simplified title'.

Hebrew language not showing - Android

I have created 2 string files one the default under res/values/strings.xml and the other under res/values-he/strings.xml. I am opening my app, while the os is configured to be in Hebrew, but still I see the values of the default strings which are in English. Is there any thing more to do?
Note: in the eclipse graphical layout editor I can choose Hebrew and see that it works fine.
Here is some of my default strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyApp</string>
<string name="title_activity_splash">MyApp</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_login">Login</string>
<string name="email">Email</string>
<string name="password">Password</string>
<string name="forgot_password">Forgot password?</string>
<string name="sign_up">Sign up</string>
<string name="login">Login</string>
.
.
.
and here is all (for now) my hebrew strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">הגדרות</string>
<string name="hello_world">שלום עולם</string>
<string name="email">דואל</string>
<string name="password">סיסמא</string>
<string name="forgot_password">שכחת סיסמא</string>
<string name="sign_up">רישום</string>
<string name="login">התחברות</string>
</resources>
Here it in eclipse:
here it on the device (device os in hebrew):
OK, you correctly have:
res/values/strings.xml
and
res/values-he/strings.xml
With the correct structure, be also sure that the strings have the very same names in each strings.xml file, or the trick won't work.
The missing strings in a translation file won't be translated and the default strings (from res/values/strings.xml) will be used instead.
For hebrew, in particular, on some devices values-he is recognized. in some others it's values-iw.
So, make a copy of values-he and name it values-iw. Keep both in your structure.
What solved the problem for me was to use the folder values-iw.

Application configuration file

I need a place where I can store basic application configuration(URIs, DB-name, external storage folder-names, etc) in XML or any other decent format.
Is it /assets folder ? If so - give a basic example of using it in conjunction with XML files.
Thanks.
Yes there is: Resources folder: res/values/strings.
There you can place all the strings you want.
To use locale specific strings create multiple value folders ending with the locale suffix.
values folder (default):
<string name="app_name">My android app name</string>
<string name="email">myemail#gmail.com</string>
<string name="contact_me">Contact me</string>
values-PT folder (portuguese strings):
<string name="app_name">My android app name in PT</string>
<string name="email">myemail#gmail.com</string>
<string name="contact_me">pt string for contact me</string>
then just use them as: yourPackage.R.string.email on your classes.

Categories

Resources