Onchange Phone language in Android my App layout change - android

when i change my phone language it effect my App also,,i want that whatever the phone language as,,not effected my App layouts,for example my App is an English language i want the app language and layouts remain same,,while phone language keep changing

Changing the language is considered a configuration change, just like rotating the device or switching the UI from light- to dark mode. Your activity is then recreated and loaded with the appropriate resources.
If you wan't to handle a configuration change yourself, you need to specify this in your manifest for your activities as stated here.
<activity android:name=".MyActivity"
android:configChanges="locale"
android:label="#string/app_name">
You can find other valid values for configChanges here.

Related

How to change locale and layout dynamically in android?

I am developing an app that uses text in 3 languages. English, Kurdish and Arabic. I am trying to change the layouts dynamically when user changes language. I have a settings screen where the user can change language that is I am not changing language from the system settings but from within my app. For example the layout should change from RTL to LTR if I switch from Kurdish to English or vice versa. I tried to use onConfiguterionchanged() but it is not getting triggered.
Changing locale: Force activity to reload resources? had the answer to the question.
I tried
Android: locale(system Language) change effect my application layouts.
Android Localization problem: Not all items in the layout update properly when switching locales,
Trying to change Android Locale on the fly.
http://www.c-sharpcorner.com/UploadFile/1e5156/how-to-change-locale-of-an-application-dynamically-in-androi/
without success.
I tried onResume() which gets triggered but the layout is not changed when the language is changed. I use the following code to change the locale. LocaleSingleton is a class that I created to hold an instance of Configuration.
#Override
protected void onResume() {
getResources().updateConfiguration(LocaleSingleton.getInstance().getConfig(), getResources().getDisplayMetrics());
AsyncData data = new AsyncData();
data.execute(String.valueOf(id), Constants.SERVER + "ad_detail.php");
super.onResume();
}
Any help is appreciated. Thanks in advance.
Edit: I have also tried to restart the activity in onResume() but I get only a black screen. Thanks again.
Add this to your activity in your manifest
<activity
android:name=".YourActivity"
android:configChanges="orientation|keyboardHidden|screenSize" >
</activity>

putting whole application in landscape mode in manifest

The line android:screenOrientation="landscape" in each activity in manifest file will put that activity in landscape.
Is there any way to put whole application in landscape in manifest? I put it in application field but didnt work.
I have an app which will only use landscape mode.
Nope. You might somehow embed it into the code before you launch your activities, but overall, the activities specification must have that setting. Look at the specification here and here.

Android - change Launcher Icon Language

I want add a settings for language to my app which is independent from system language.
I could manage to change language of anything but the launcher icon is still in system language.
Is it possible anyhow to change that icon language?
Metin
Let's say that you are supporting N languages with this dubious feature.
You will need N entries in your manifest for the launcher activity. Each of those N entries will need an android:label pointing to a string that represents what you want displayed when your app is configured for -such-and-so language. You would then use PackageManager and setComponentEnabledSetting() to disable the old activity and enable the new one.
It is conceivable that you could use one <activity> element and N <activity-alias> elements to achieve your objective, but I am uncertain as to whether you can enable and disable activity aliases.

My Android app rotates even if screen rotation is disabled in the OS. How can I fix this?

I am developing an Android app that has full support for landscape mode. All of my activities have the following properties set in the manifest:
android:configChanges="keyboardHidden|locale|orientation"
android:screenOrientation="sensor"
However, if I disable rotation in the phone's Screen settings, my app still rotates when the phone is rotated. This kind of bothers me; it seems like the whole point of a system-level setting is moot if it can be overriden by an individual app. How can I fix this so it follows the system-level setting while still behaving properly if screen rotation is enabled on the phone?
You could try using
android:screenOrientation="user"
You can try other way like this ,
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
apply these attributes after the activity name in AndroidManifest.xml file.
you can add android:screenOrientation="user" and make sure there is no SCREEN_ORIENTATION_SENSOR in the java code or manifest.

How to avoid changing of image and layout position when changing from portrait to landscape mode in android

I have problem while using lanscape mode in android.How to avoid changing of image position changing from portrait to landscape mode in android.Normally landscape4 and portrait mode is good.If we goes from one mode to another then position of images are changed. Please help me
The activity in which you are showing image, register that Activity in Android Manifest file as:
<activity
android:name="com.android.YourActivity"
android:screenOrientation="portrait">
</activity>
In this way, it will force the activity to stay in Portrait mode only.
The orientation changes causes the running activity to restart.The restart behavior is designed to help your application adapt to new configurations by automatically reloading your application with alternative resources that match the new device configuration. Hence resource intensive.
Depending on how you want you app to behave and the device performance you can handle the orientation change(config changes as a whole) in following ways:
Fixed orientation: If you want your app to have a fixed orientation in landscape or portrait mode. For this you need to set this attribute in the manifest file under the activity tag.
android:screenOrientation="portrait"
or
android:screenOrientation="landscape"
Handling the Configuration Change Yourself: You can handle the orientation change yourself if your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the activity restart, then you can declare that your activity handles the configuration change itself, which prevents the system from restarting your activity.
For this you need to declare this in the manifest file:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"/>
and you need to override the onConfigurationChanged() method of the activity.
** use this as the last resort as every thing needs to be handled by you.
Default behavior: You can let android handle the config changes choosing the alternative resources from the resource folder. You just need to provide these alternate resources for landscape and portrait mode.

Categories

Resources