i want change language of application settings.
public boolean onpreferencechange(preference preference, object value) { string stringvalue = value.tostring(); if (preference instanceof listpreference) { // list preferences, correct display value in // preference's 'entries' list. listpreference listpreference = (listpreference) preference; int index = listpreference.findindexofvalue(stringvalue); // set summary reflect new value. preference.setsummary(index >= 0 ? listpreference.getentries()[index]: null); .............
here, inside settings activity how can access configurations , locale of application change it's language.
fyi, have translated strings in values.
check code
public static final string arabic = "ar"; public static final string english = "en"; public static void changeloc(activity context, int flaglang) { resources res = context.getresources(); // change locale settings in app. displaymetrics dm = res.getdisplaymetrics(); android.content.res.configuration conf = res.getconfiguration(); if(flaglang == 0) { //english conf.locale = new locale(english); } else { //arabic conf.locale = new locale(arabic); } res.updateconfiguration(conf, dm); }
Comments
Post a Comment