I have an app that has a button resposible for changing the language inside this app. The only thing that is immune to changes is DatePicker
.
Code that change my app's language:
polishLanguage.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
restartActivityInLanguage("pl");
}
});
private void restartActivityInLanguage(String language) {
Locale locale = new Locale(language);
Configuration config = new Configuration();
config.locale = locale;
config.setLocale(locale);
Resources resources = getResources();
resources.updateConfiguration(config, resources.getDisplayMetrics());
getActivity().recreate();
}
DatePicker code in xml:
<DatePicker
android:id="@+id/datePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
android:calendarViewShown="false"
android:datePickerMode="spinner" />
DatePicker code in java:
product_expirationDate_datepicker = new DatePicker(getActivity().getApplicationContext());
Calendar today = Calendar.getInstance();
long now = today.getTimeInMillis();
product_expirationDate_datepicker.setMinDate(now);
product_expirationDate_datepicker.init(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth) {
int selctedMonth = month + 1;
expirationDateString = (product_expirationDate_datepicker.getYear() + "-" + selctedMonth + "-" + product_expirationDate_datepicker.getDayOfMonth());
Log.e("onDateChanged", "expirationDateString: " + expirationDateString);
HAS_DATE_BEEN_CHANGED = true;
}
});
There's no error in logcat, the languaege just doesn't change. I have already tried:
Set language to French in android DatePickerDialog and
https://gist.github.com/gilbertwat/4631571 but nothing works.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…