I'm using a DatePickerDialog in my code and set the Locale of the app right before using it and in onCreate of my base activity. it's working perfectly in Arabic as it uses Arabic (called Hindi format or Eastern Arabic numerals) and Arabic strings as shown in the screenshot But I need to display English numbers in the DatePickerDialog itself when the locale is Arabic while keeping the Arabic strings upon client request as the Arabic numbers isn't used in his country which where the app will operate in.
Meaning that all ٠, ١, ٢, ٣, ٤, ٥, ٦, ٧, ٨, ٩ should be replaced with 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, is this possible to achieve?
Here's my code:
BaseActivity
public abstract class BaseActivity extends AppCompatActivity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LocalizationHelper.setLocal(this);
}
}
LocalizationHelper.java
public class LocalizationHelper {
public static void setLocal(Context context) {
Locale locale = new Locale(getLanguage(context), "LY");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
Resources resources = context.getResources();
resources.updateConfiguration(config, resources.getDisplayMetrics());
}
public static String getLanguage(Context context) {
return SharedPreferencesHelper.getLanguage(context);
}
}
Calling the dialog:
public static void showDatePicker(Context context, OnDialogActionCallBack onDialogActionCallBack, DashboardFilterDate date) {
LocalizationHelper.setLocal(context);
final Calendar c = Calendar.getInstance();
DatePickerDialog pickerDialog = new DatePickerDialog(context, (view, year1, month1, dayOfMonth) -> onDialogActionCallBack.onPositiveButtonClicked(dayOfMonth, month1, year1),
date != null ? date.getYear() : c.get(Calendar.YEAR),
date != null ? date.getMonth() : c.get(Calendar.MONTH),
date != null ? date.getDay() : c.get(Calendar.DAY_OF_MONTH));
pickerDialog.show();
}

if you want to change the result to english numbers you can use this code