I would like to create a spinner in Android XML, which will have list of the phone codes (ex. USA - +1), and after choosing the phone code at the bottom I want a program to show the country name of the chosen phone code. It should work automatically, which means whenever I change the phone code, it will change the name of the Country.
Thanks!
you can use 3rd party library for this.
https://github.com/hbb20/CountryCodePickerProject/blob/master/README.md?fbclid=IwAR1tz_D3PTEUyy2-zaGG0QTZWda_8ss9nbSml-z7zyI3gULLFsibIlRhujs
if you want to you own program you can try i can help if any difficult situation.
Related
This is which I actually want in our app but I am too little bit confuse in implementation. Please guide me. I am doing my project in kotlin
This is which I have
As I can see in your example image, you are trying to create a country picker. For this, you can use this dependency in your code
https://github.com/hbb20/CountryCodePickerProject
this dependency makes it very easy to implement the country picker of your project, if you don't want to add any dependency for country picker then you have to add all the country flags in your drawable folder and maintain a list with flag name, country code, and country name.
Overview
AFAIK on Android you have twi ways to set the texts of your application:
You can use string.xml with different locales
You can download strings from server and set every label with a setText(language.text) but it will be a pain
The problem might sussist if you have to change a text of your published application without re-publishing it; for example if you want to change for a specific translation a small text without any functionality change. (ie: you might notice that you wrote "Take picure" instead of "Take picture").
Library
i18next is a good library to manage translations dinamically from server, but you still have to add the text for each label you got.
So, my question is
Still AFAIK, there is no way to do it natively, but is there a low level library or a workaround that allows to replace a string in your string.xml with some downloaded text?
Another option could be to make our label text to point instead of at #string/myValue to something like #myresource.pathtovalue.
Honestly I think this could be an huge improvement for application, is there something useful?
I am very new for developing the multi-language oriented Android APP. This is the first time i am going to support my app in multi-support language app. I need some clarification for developing the multi-language support app. Already i have some ideas before initiate the development.
Single APK with Localization like will make the multiple String.xml and include it in inside of the app and based the member selection of language its automatically invokes and works.
All language strings values will retain in app server (back-end) and will raise the Rest-API request and get those values and change it inside of the entire app (all screens) if member click and change the language inside of the app.
Main concern is if anything needs to change in future then Idea2 is best way. We will just change in back-end side it will be appeared in client side. But if we are going Idea1 and wants to change then we need to put the new build only.
Which one is best approach and recommended way to develop?
You will need to create different String.xml depending the languages you want to target as JDenais says, in my app i have the following
for example the first arab string consist in the same as Strings.xml but with all in arab, now, you only need to call one string in your xml files and it will just select where to grab depending on the phone language. Or in default the language from where the app was downloaded by google play, in fact, they are all the same strings.xml , so you dont need to specify which one you want to pull the translated text from, just replicate your main strings.xml in your other strings.xml and then the phone will decide where to pull the data.
Also please read the official doc on how to accomplish this https://developer.android.com/training/basics/supporting-devices/languages
Also please check the language ISO Codes here
What is the list of supported languages/locales on Android?
All your texts should be packaged in the APK in different String.xml files. Forget about receiving texts from a backend. It would be a lot of extra work for limited gain and with added risks of failure.
The framework takes care of selecting the appropriate string.xml file and offers support for needed use cases like plurals.
right click the values folder and choose new-> values resource file -> locale -> choose the language you want and name it strings.
copy the strings from the original string file to the new file and change them to the new language just the strings
make sure that the view xml files have their text set as "#string/the_name of the string" not hard coded
hey mates i am Trying to Use other Languages in my App (Persian), and i want it to be Both phone Device Dependant and and Not being Dependant (Phone be English but app be Persian), So if i simply Use R.String.myOtherLang, the App's Out put is some meaningless Number like it Doesnt recognize the language, if i Use getResources().getString(R.String.myOtherLang) , it returns Could not find the Resource Exception if the App's Language be not same (Using values-fa), But when i Enter the Text in Persian directly to the XML layout file, it works Fine, Is there any Way i can Get the language Depenancy from The Phone to User Choice?
OK, you need to you put a file named strings.xml in both values-en and in values-fa.
Then in code you can set the locale to en or fa, respectively and finally apply by restarting the activity (simply finish it before restarting it).
Then it's: getResources().getString(R.String.myString) (note that myString has to have the same name in both the strings files)
I have edit text element that will get the phone number, I need the phone number to be include country code in +xxx format. I am using android:inputType="phone"
how I can force the input to have that +Countrycode in the number?
I want something like Google contacts if possible or similar. If instead of flag just the country code is possible , that is also OK.
Finally I used IntlPhoneInput. Although I had to tweak it for my usage but this is a nice library.
Its available on gradle.
compile 'net.rimoto:intlphoneinput:0.9.3'