Android 多语种适配框架,兼容高版本,适配第三方库语种
7.0 以下,需要在 build.gradle 文件中加入allprojects {
repositories {
// JitPack 远程仓库:https://jitpack.io
maven { url 'https://jitpack.io' }
}
}7.0 及以上,则需要在 settings.gradle 文件中加入dependencyResolutionManagement {
repositories {
// JitPack 远程仓库:https://jitpack.io
maven { url 'https://jitpack.io' }
}
}build.gradle 文件中加入远程依赖dependencies {
// 语种切换框架:https://github.com/getActivity/MultiLanguages
implementation 'com.github.getActivity:MultiLanguages:10.2'
}public final class XxxApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// 初始化语种切换框架
MultiLanguages.init(this);
}
}@Override
protected void attachBaseContext(Context base) {
// 绑定语种
super.attachBaseContext(MultiLanguages.attach(base));
}@Override
protected void attachBaseContext(Context newBase) {
// 绑定语种
super.attachBaseContext(MultiLanguages.attach(newBase));
}只要是 Context 的子类都需要重写,Service 也雷同,这里不再赘述
温馨提示:Fragment 不需要重写此方法,因为它不是 Context 的子类
// 设置当前的语种(返回 true 表示需要重启 App)
MultiLanguages.setAppLanguage(Context context, Locale locale);
// 获取当前的语种
MultiLanguages.getAppLanguage(Context context);
// 跟随系统语种(返回 true 表示需要重启 App)
MultiLanguages.clearAppLanguage(Context context);…// 设置语种变化监听器
MultiLanguages.setOnLanguageListener(new OnLanguageListener() {
@Override
public void onAppLocaleChange(Locale oldLocale, Locale newLocale) {
Log.d("MultiLanguages", "监听到应用切换了语种,旧语种:" + oldLocale + ",新语种:" + newLocale);
}
@Override
public void onSystemLocaleChange(Locale oldLocale, Locale newLocale) {
Log.d("MultiLanguages", "监听到系统切换了语种,旧语种:" + oldLocale + ",新语种:" + newLocale + ",是否跟随系统:" + MultiLanguages.isSystemLanguage());
}
});…安卓技术中台:AndroidProject
安卓技术中台 Kt 版:AndroidProject-Kotlin
权限框架:XXPermissions
吐司框架:Toaster
网络框架:EasyHttp
标题栏框架:TitleBar
悬浮窗框架:EasyWindow
设备兼容框架:DeviceCompat
Shape 框架:ShapeView
Gson 解析容错:GsonFactory
日志查看框架:Logcat
Android 命令行工具集:AndroidCmdTools
Android 版本适配:AndroidVersionAdapter
Android 代码规范:AndroidCodeStandard
Android 资源大汇总:AndroidIndex
Android 开源排行榜:AndroidGithubBoss
Studio 精品插件:StudioPlugins
表情包大集合:EmojiPackage
AI 资源大汇总:AiIndex
省市区 Json 数据:ProvinceJson
Markdown 语法文档:MarkdownDoc
Copyright 2019 Huang JinQun
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.No open issues yet, or sync has not completed.