Skip to content

Commit 7a12693

Browse files
committed
修复某些情况下切换语种后配置没有保存的问题
1 parent be92a8f commit 7a12693

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

MultiLanguages.apk

12 Bytes
Binary file not shown.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 语种切换框架
22

3-
* 码云地址:[Gitee](https://gitee.com/getActivity/MultiLanguages)
3+
* 项目地址:[Github](https://github.com/getActivity/MultiLanguages)[码云](https://gitee.com/getActivity/MultiLanguages)
44

55
* [点击此处下载Demo](MultiLanguages.apk)
66

@@ -26,7 +26,7 @@ allprojects {
2626
```groovy
2727
dependencies {
2828
// 语种切换框架:https://github.com/getActivity/MultiLanguages
29-
implementation 'com.github.getActivity:MultiLanguages:6.8'
29+
implementation 'com.github.getActivity:MultiLanguages:6.9'
3030
}
3131
```
3232

@@ -199,6 +199,8 @@ public final class LanguagesWebView extends WebView {
199199

200200
* 悬浮窗框架:[XToast](https://github.com/getActivity/XToast)
201201

202+
* Shape 框架:[ShapeView](https://github.com/getActivity/ShapeView)
203+
202204
* Gson 解析容错:[GsonFactory](https://github.com/getActivity/GsonFactory)
203205

204206
* 日志查看框架:[Logcat](https://github.com/getActivity/Logcat)

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hjq.language.demo"
88
minSdkVersion 16
99
targetSdkVersion 30
10-
versionCode 68
11-
versionName "6.8"
10+
versionCode 69
11+
versionName "6.9"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414

app/src/main/res/layout/activity_main.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@
4141
android:layout_width="wrap_content"
4242
android:layout_height="wrap_content"
4343
android:checked="true"
44-
android:text="自动" />
44+
android:text="跟随系统" />
4545

4646
<RadioButton
4747
android:id="@+id/rb_main_language_cn"
4848
android:layout_width="wrap_content"
4949
android:layout_height="wrap_content"
50-
android:layout_marginLeft="20dp"
50+
android:layout_marginLeft="15dp"
5151
android:text="简体" />
5252

5353
<RadioButton
5454
android:id="@+id/rb_main_language_tw"
5555
android:layout_width="wrap_content"
5656
android:layout_height="wrap_content"
57-
android:layout_marginLeft="20dp"
57+
android:layout_marginLeft="15dp"
5858
android:text="繁体" />
5959

6060
<RadioButton
6161
android:id="@+id/rb_main_language_en"
6262
android:layout_width="wrap_content"
6363
android:layout_height="wrap_content"
64-
android:layout_marginLeft="20dp"
64+
android:layout_marginLeft="15dp"
6565
android:text="英语" />
6666

6767
</RadioGroup>

library/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ android {
55

66
defaultConfig {
77
minSdkVersion 14
8-
versionCode 68
9-
versionName "6.8"
8+
versionCode 69
9+
versionName "6.9"
1010
}
1111

1212
android.libraryVariants.all { variant ->
1313
// aar 输出文件名配置
1414
variant.outputs.all { output ->
15-
outputFileName = "language-${android.defaultConfig.versionName}.aar"
15+
outputFileName = "${rootProject.name}-${android.defaultConfig.versionName}.aar"
1616
}
1717
}
1818
}

library/src/main/java/com/hjq/language/MultiLanguages.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public static void updateAppLanguage(Context context) {
5858
* 更新 Resources 的语种
5959
*/
6060
public static void updateAppLanguage(Resources resources) {
61+
if (resources == null) {
62+
return;
63+
}
6164
if (LanguagesUtils.getLocale(resources.getConfiguration()).equals(getAppLanguage())) {
6265
return;
6366
}
@@ -77,6 +80,7 @@ public static Locale getAppLanguage() {
7780
* @return 语种是否发生改变了
7881
*/
7982
public static boolean setAppLanguage(Context context, Locale newLocale) {
83+
LanguagesConfig.setAppLanguage(context, newLocale);
8084
if (LanguagesUtils.getLocale(context).equals(newLocale)) {
8185
return false;
8286
}
@@ -88,7 +92,7 @@ public static boolean setAppLanguage(Context context, Locale newLocale) {
8892
// 更新 Application 的语种
8993
LanguagesUtils.updateLanguages(sApplication.getResources(), newLocale);
9094
}
91-
LanguagesConfig.setAppLanguage(context, newLocale);
95+
9296
LanguagesUtils.setDefaultLocale(context);
9397
if (sLanguageListener != null) {
9498
sLanguageListener.onAppLocaleChange(oldLocale, newLocale);
@@ -166,7 +170,7 @@ public static void setOnLanguageListener(OnLanguageListener listener) {
166170
}
167171

168172
/**
169-
* 设置保存的 SharedPreferences 文件名
173+
* 设置保存的 SharedPreferences 文件名(请在 Application 初始化之前设置,可以放在 Application 中的代码块或者静态代码块)
170174
*/
171175
public static void setSharedPreferencesName(String name) {
172176
LanguagesConfig.setSharedPreferencesName(name);

0 commit comments

Comments
 (0)