项目历经9个月的演化,终于从一开始为宝可梦的那样记账研究的语言切换而写的 Demo 进化成第三方库。
这是我的第一个开源第三方库,说起来还挺激动的(嗯…失眠了…)~
allprojects {
repositories {
// ...
maven { url "https://dl.bintray.com/rebornq/maven/" }
}
}
implementation 'com.mallotec.reb:plugin-language:{last-version}'
注意: {last-version} 要替换为最新版本号 ,最新版本链接: https://bintray.com/rebornq/maven/plugin-language/_latestVersion
由于本插件还用了 androidx.preference ,因此需要引入 Preference 相关依赖
// preference implementation 'androidx.preference:preference:1.1.0'
Application 继承 BaseApplication Activity 继承 BaseAppCompactActivity 添加混淆规则
# LanguagePlugin 混淆规则
-keep class com.mallotec.reb.languageplugin.** { *; }
-dontwarn com.mallotec.reb.languageplugin.** 一句代码调用切换语言:
// 应用切换的语言 LocaleManageUtil.applyLanguage(this, which.toString())
注意:这里的 this 必须是 Activity 的 Context , which 是所选的语言标记
效果图:
更多请查看本项目的 Demo