Home>
Language change for "DateUtils.formatDateTime" is not applied only to Android4.1.2 (API16).
Note that Android 4.4.4, 7, and 8 will function without problems in actual machine tests.
// Change the language of English language other than English to UK
boolean localeChangeFlg = false;
if ((Globals.getAppContext (). getString (R.string.language_str) .equals ("english"))&&locale.getDefault (). getLanguage (). equals (Locale.ENGLISH.getLanguage ()) == false) {
defLocale = Locale.getDefault ();
Locale locale = Locale.UK;
Locale.setDefault (locale);
Configuration config = new Configuration ();
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {
config.setLocale (locale);
config.setLayoutDirection (locale);
} else {
config.locale = locale;
}
Globals.getAppContext (). GetResources (). UpdateConfiguration (config, null);
localeChangeFlg = true;
}
// Display year/month/day
cl_now = Calendar.getInstance ();
String wkDate;
if (Build.VERSION.SDK_INT>16) {
wkDate = DateUtils.formatDateTime (this, cl_now.getTimeInMillis (), FORMAT_SHOW_YEAR | FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL);
} else {
if (getString (R.string.language_str) .equals ("japanese")) {
wkDate = DateUtils.formatDateTime (this, cl_now.getTimeInMillis (), FORMAT_SHOW_YEAR | FORMAT_SHOW_DATE);
wkDate = wkDate + getString (R.string.stParenthesis) + DateUtils.formatDateTime (this, cl_now.getTimeInMillis (), FORMAT_SHOW_WEEKDAY | FORMAT_ABBREV_ALL) + getString (R.string.edParenthesis);
} else {
wkDate = DateUtils.formatDateTime (this, cl_now.getTimeInMillis (), FORMAT_SHOW_YEAR | FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY);
}
}
TextView t_dateAndWeek = findViewById (R.id.t_dateAndWeek);
t_dateAndWeek.setText (wkDate);
// If the language is changed, restore it
if (localeChangeFlg) {
Locale locale = defLocale;
Locale.setDefault (locale);
Configuration config = new Configuration ();
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {
config.setLocale (locale);
config.setLayoutDirection (locale);
} else {
config.locale = locale;
}
Globals.getAppContext (). GetResources (). UpdateConfiguration (config, null);
}
Do not use "Locale.ENGLISH" instead of "Locale.UK"
Supplemental information (FW/tool version etc.)Android Studio3.4
API level 14 to 28
-
Answer # 1
Related articles
- java - i want to dynamically change the color of the entire background in android studio
- i want to write a code that uses javascript to change the display contents of the choices of choice 2 depending on the items sel
- java - when you do not want to change the value of the property (field)
- change java output text color
- java i want to change the format of the value called from a different file
- css - i cannot change the size of the hamburger menu applied to the smartphone size
- java - i want to change the height of the red part of the screen display after the search results
- java - how to change url for server access
- java language time limit does not work
- java - i want to change the background color of a row in a thymeleaf table under certain conditions
- java - language characteristics "processing speed" "safety" "coding speed"
- change from javaapplet to application
- java - change build from maven to ant
- java - i want to change the screen when clicking a button in android studio
- java - i want to change the text of the answer button depending on the problem
- java - i want to change the color when i press the like button and keep the color changed
- java - change every time you press the color of the android studio button
- java - i want to take out the character string in arraylist and change it to a number
- i want to make sure that the button to change the color is installed normally in javafx
- java - recommended programming language for automatically creating subtitles using voice recognition, etc
Related questions
- java : Frame in ListView items
- java : DecimalFormat, how to customize the display of the result
- java : LayoutView visual editor problems
- java : Error sending email with file attachment
- java : Change button color in Android-Studio
- java : Moving to a fragment with memorizing actions in the previous fragment
- java : Why socket data transmission does not work
- java : Error when entering zero coefficients in the Diophantine equation
- java : How to parse huge JSON?
- java : Help restore displaying textView
If you look at the implementation of DateUtils.formatDateTime as of API16, it seems that the format language is determined based on the resources acquired with Resources.getSystem (). So, please add processing to rewrite the Configuration of Resources.getSystem () as follows.