Step 1:Create One java class which extends from 'Application'
public class LocaleApplication extends Application{
private Locale mLocale = null;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (mLocale != null) {
newConfig.locale = mLocale;
Locale.setDefault(mLocale);
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}
}
@Override
public void onCreate() {
super.onCreate();
updateLocale(BuildConfig.LOCALE);
}
public void updateLocale(Locale locale) {
Configuration config = getBaseContext().getResources().getConfiguration();
if (!config.locale.equals(locale)) {
mLocale = new Locale(locale.getLanguage(),locale.getCountry());
Locale.setDefault(mLocale);
config.locale = mLocale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
// reload challenge and achievement strings - these were created with the previous locale
}
}
}
Step 2: Mention this class name in Android manifest file under <application> tag
<application
android:name="LocaleApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Step 3: Take appropriate resource folders like values-es-rCO,values-el etc.
Step 4: Add below steps in build.gradle for resource configurations.
defaultConfig {
applicationId "com.example.ankitpr1.forcelocalisation_android"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
buildConfigField 'java.util.Locale', 'LOCALE_SPANISH_LATAM', 'new java.util.Locale(\"es\",\"US\")'
buildConfigField 'java.util.Locale', 'LOCALE_Greek', 'new java.util.Locale(\"el\")'
}
productFlavors {
esus{
applicationId 'com.colombia.us'
resConfigs 'es-rCO'
buildConfigField 'java.util.Locale', 'LOCALE', 'new java.util.Locale(\"es\",\"CO\")'
versionCode 3
versionName "3.0"
// ! any change in Locale, should be applied in defaultConfig as well
}
Greek {
applicationId 'com.test.greek'
resConfigs 'el'
buildConfigField 'java.util.Locale', 'LOCALE', 'new java.util.Locale(\"el\")'
versionCode 2
versionName "2.1"
l
}
}
//List all flavours in project to be used for check current flavour against others
productFlavours.all {
flavour ->
def flavourName = String.valueOf(flavour.name)
defaultConfig.buildConfigField 'String', 'Flavour_' + flavourName , '\"' + flavourName + '\"'
}
Showing posts with label android studio. Show all posts
Showing posts with label android studio. Show all posts
Wednesday, August 3, 2016
Force Localisation Android
Tuesday, March 1, 2016
Build variant type according to Locale
Add below code under android--defaultConfig in build.gradle file
buildConfigField 'java.util.Locale', 'LOCALE_SPANISH_LATAM', 'new java.util.Locale(\"es\",\"US\")'
productFlavors {
esus{
applicationId 'com.praveena.test.us'
resConfigs 'es-rUS'
buildConfigField 'java.util.Locale', 'LOCALE', 'new java.util.Locale(\"es\",\"US\")'
}
}
By using this we can select the build variant type while running.
Wednesday, May 6, 2015
Android Studio shortcuts like Eclipse
As far we are good to use the shortcut controls in eclipse.
Now we are
migrating to Android studio where the shortcuts are different while comparing
Android studio and Eclipse.
Please follow the below steps to enable the eclipse
shortcut controls in Android studio if you want to use the same eclipse controls
in Android Studio.
- Click on File menu
- Navigate to “Settings”
- Click on Keymap section which is available in left side panel
- You can see the keymaps dropdown on the right side panel. Select “Eclipse” from
- Finally, save the settings by clicking on OK button.
Now you will be able to use the same eclipse controls in Android studio.
Goto Settings -->Security -->Owners Info --> Enable show owners info on lock screen and enter information there like emergency contact numbers etc.
Subscribe to:
Posts (Atom)