Android Layout Multicolor - android

i am currently working on one Android Application and i have to set layout according to country like if application is for Korea layout color must be blue and for india layout color must be red.
So how can i achieve that?
i know about multiple language
values-kr // for Korea
values //for English
values-fr // for french
but for layout i don't know.
Help Me.
Thanks in Advance

You can create a Style for each Values or in java code programming you can use a simple if statement that detects your location inside "oncreate method" and setbackground layout according to what you want using a drawable.

You have to determine your system language. You can use
Locale.getDefault().getLanguage();
to get the usual language code (e.g. "de", "en").
Then, create a base Activity for your app and override onCreate to set the theme according to your system language. Derive all your other activities from this base Activity. Check this tutorial.

follow type of languages
res/values/strings.xml
Contains English text for all the strings that the application uses,
including text for a string named title.
res/values-fr/strings.xml
Contain French text for all the strings, including title.
res/values-ja/strings.xml
Contain Japanese text for all the strings except title.
How to display Korean Words in android app

You may use this piece of code:
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String locale = tm.getSimCountryIso();
and choose:
if (locale.equals(pk))
{
view = inflater.inflate(R.layout.hazel_quick_form, container, false);
} //fragment

Take example of TextView.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#color/textcolor" />
you can have colors.xml file in different locale folders like values , values-fr etc.
In example textview #color/textcolor can be defined with those saperated colors.xml files with different colors for different locales.
look at this.
Android will do the next magic automatically based on locale.

Related

Localization text direction supportsrtl:false in arabic in android for string resources not working

I am trying to localize my app in arabic by using **
android:supportsRtl:false
** in my manifest file.It actually works for all the strings declared in the xml layout i.e **
android:text="#string/done_btn"
**and all the arabic localized strings are written ltr(left to Right) but those strings which are written programmatically using resources strings i.e
getString(R.id.name)
are localized but it is using it's default written type i.e rtl(Right to left) instead of ltr(left to Right) thereby destroying the layout and design of the page.
N.B:1> i already tried setting android:layoutDirection="ltr" or android:textDirection="ltr" to the textview with localized string or the container layout which it holds.
Any help would be highly appreciated.

Arabic numbers with ar-ae and ar-sa locale in Android

As I asked in the following question:
Arabic number in Arabic text in Android
if I use the arabic locale ar-ae or ar-sa the numbers are shown using Hindu-Arabic numbers.
I need to show the digits like in English: "1234567890".
I used to use the trick of setting the numeral extension
Locale.Builder builder = new Locale.Builder();
builder.setLocale(savedLocale).setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-latn");
Locale locale = builder.build();
The problem is that after you do that the resource lookup gets broken and with Nougat it just does not work anymore.
Is there a way to see the "normal" digits even using the Arabic locale for ae and sa?
One workaround is to replace the font for the digit characters. You'll be able to keep your original font for the text.
I would recommend to do that in a clean way by extending TypeFaceSpan.
Take a look at this question.
If you need some code, let me know and I'll update this answer.
You should trust the locale you are using. If you are specifically targetting ar_SA then you should let it render things the way it's meant to for that country. If you just want Arabic language but want the western Arabic numbers then try a locale from one of the western Arab countries, ar_MA for example.
For now what I did is to use a custom font and to replace in the file for the custom font the digits with the Hindu-Arabic numbers with the correspondent char for the "western-Arabic" number.
Please check
how to remove characters from a font file?
EDIT
It is now possible to use a locale like for example:
<item>ar-AE-u-nu-latn</item> <!-- Arabic (United Arab Emirates, Western Digits) -->
This is taken from here

Forcing language to not change

I have app in android studio and When i install APK and Language is English,
it show language of app like i want, but when phone language is different like Persian, it show other language in app and i don't want it...
how i can force app to use same English even language of phone changed?
my application is in Android studio and just one line have problem, mean there is a line words in application, and when i change language phone, it change to a different language same i don't want.
this is my main.xml (same line code
<TextView
android:id="#+id/diffText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dhuhar After one hour 10 min"
android:textColor="#ffffff"
android:textSize="16dip"
android:textStyle="bold"></TextView>
</LinearLayout>
And this one is not available in my string.xml, it mean it not translated, correct?
and cause "one hour 10min" is not stable, there is easy way i force it to use for all language same use for english?
I set below code in oncreate and solved
Locale.setDefault(Locale.ENGLISH);
If you want only english for all languages, dont set different language xml.. Just provide only default strings.xml.. app will show what ever text in strings.xml.
If you don't define your string in other language files (only write <string name="yourstring" translatable="false">Your english string</string>) then you will get your expected behavior.
That is because it takes the strings from values/ if they are not available in the specific folder for the current language (e.g. values-de/)

Text in android app (beginner...)

My problem is very simple: I've started an app for playing Darts. The app will have several activities ('pages').
One page will be about the rules of the game. I'll be using a scroll layout because it's quite some text. But how to get the text there?!
I assume working with strings is not the best way? Do I use the XML file to get the text on screen then or does it work via Java (Assetmanager)?
Maybe there are sample apps in which large chunks of text are used?
I know this really might seem like a trivial question but I haven't a clue where to begin.
Thanks in advance!
You should put your string in your strings.xml in your res\values folder.
You can define strings by ID which allows easier internationalization (i18n), so that you can easily adjust the strings used in your app to locale (which is done automatically using resource identifiers, and it falls back to strings.xml if it can't find a strings-hu.xml in case you have Hungarian locale set as system language).
You can also define string-array and the like in XMLs. Then all you need is create a layout XML with a ScrollView in it that has a TextView in it and then you set android:text="#string/rules" for that TextView and you're done.
It is so simple my friend.
You can simply use TextView and in "android:text" you refer to the string that you delared in strings.xml file (by its name)
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="#string/text_name"
/>
If your text is dynamic, you can modify it in Java code!
Make a String Resource like this.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="string1"> your text </string>
<string name="string2"> your text </string>
</resources>
and access like this if you are in Activity.
getResources().getString(R.string.string1);
If you are a begginer you should read some tutorials after post a question...
I give you a three nice tutorials below :
Want to Learn How to Program for Android? Start Here
Android Programming Tutorial
Android Development with Android Studio or Eclipse ADT
About your question, if you don't know how to use the string.xml resource just read the string-resource guide
Hope it helps.

Is it possible to use android:inputType with a string resource

I'm making an android app for multiple languages. I would like to set the inputType for an EditText view to be different based on the keyboard language. In the XML file I've tried:
android:inputType="#string/xyz"
and in the Strings resource file string xyz would be
<string name="xyz">number</string>
I was hoping that this was a smart idea for easily changing the input type bases on language. For example, if the language were English I would set xyz to letters, but in Japanese I would have xyz as numbers. I was trying to avoid doing this programmatically because as soon as I start entering input filters in code much of my XML settings are ignored, even if they are not directly overridden by the new code.
I get an error though when I try to call this string resource to the inputType. Any assistance would be greatly appreciated.
Yes you can achieve this programmatically since inputType can take an integer value. Here is the implementation it is actually so easy.
TYPE_CLASS_TEXT has a constant value: 1
TYPE_CLASS_NUMBER has constant value: 2
This is the value your strings.xml (which you are going to localise):
For example:
input_type value in strings for English (text):
<string name="input_type">1</string>
input_type value in strings for Japanese (number):
<string name="input_type">2</string>
In your Activity, declare your EditText and set the inputType from strings.xml so it will be set according to the localisation:
editText = (EditText)findViewById(R.id.editText1);
editText.setInputType(Integer.parseInt(getResources().
getString(R.string.input_type)));
No, you cannot do this. The android:inputType attribute is defined as using flags that are also defined by Android. You cannot provide an arbitrary string value for this attribute, you can only use those pre-defined flags.
You can do it only via XML but you have to use an integer and not a string resource:
In your value folder
<integer name="myInputType">12</integer> <!-- numberPassword -->
In your layout
android:inputType="#integer/myInputType"
The integer values are listed here: https://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
Also, you can use (and override) style for your EditText (with attrs) for each language qualificator
f.e.
<style name="PinCodeInputType">
<item name="android:inputType">numberDecimal</item>
</style>
<EditText
android:id="#+id/code"
style="#style/PinCodeInputType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

Categories

Resources