TUIKit
默认自带 英语、简体中文 和 阿拉伯语 语言包,作为界面展示语言。英文 | 阿拉伯语 | 简体中文 |
| | |
TUIKit
即可,无需额外步骤。组件内部语言会跟随系统语言。public class MyApplication extends Application {@Overrideprotected void onCreate() {super.onCreate();TUIThemeManager.getInstance().changeLanguage(this, TUIThemeManager.LANGUAGE_ZH_CN);}/*** The available language options are enumerated as follows:* TUIThemeManager.LANGUAGE_EN ---- English* TUIThemeManager.LANGUAGE_ZH_CN ---- Simplified Chinese* TUIThemeManager.LANGUAGE_AR ---- Arabic*/}
changeLanguage
方法并不会自动刷新 UI,需要获取字符串之后重新设置到控件上才能生效。TUIThemeManager.getInstance().changeLanguage(context, TUIThemeManager.LANGUAGE_ZH_CN);System.exit(0);Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());context.startActivity(intent);
setThemeInternal
方法中调用以下代码解决此问题:setWebViewLanguage(appContext);
private void setThemeInternal(Context context) {if (context == null) {return;}Context appContext = context.getApplicationContext();if (!isInit) {isInit = true;if (appContext instanceof Application) {((Application) appContext).registerActivityLifecycleCallbacks(new ThemeAndLanguageCallback());}/*** add code here begin*/setWebViewLanguage(appContext);/*** add code here end*/Locale defaultLocale = getLocale(appContext);SPUtils spUtils = SPUtils.getInstance(SP_THEME_AND_LANGUAGE_NAME);currentLanguage = spUtils.getString(SP_KEY_LANGUAGE, defaultLocale.getLanguage());currentThemeID = spUtils.getInt(SP_KEY_THEME, THEME_LIGHT);// The language only needs to be initialized onceapplyLanguage(appContext);}// The theme needs to be updated multiple timesapplyTheme(appContext);}
TUIGroup
组件添加韩语语言包为例,讲解新增语言包和自定义翻译的流程。TUIGroup
组件目录下,右键菜单中新增 Android Resource File:strings
,由 Locale
维度创建资源目录:values-ko-rKR/strings.xml
。values-ko-rKR/strings.xml
,现在把 values/strings.xml
文件中的内容复制到 values-ko-rKR/strings.xml
,用韩语替换对应的英文,如图所示:name
是相同的,具体内容可以自定义翻译。TUIKit
即可,将手机默认语言设置为韩语后启动 App ,App 语言可以自动显示为韩语。TUIKit
界面的语言为韩语,应该先在 Appliction
初始化时向语言管理器中添加韩语,然后再设置 TUIKit
界面的语言为韩语:public class MyApplication extends Application {@Overrideprotected void onCreate() {super.onCreate();// Add KoreanTUIThemeManager.addLanguage("ko-rKR", Locale.KOREA);// Change the application language to Korean.TUIThemeManager.getInstance().changeLanguage(this, "ko-rKR");}}
本页内容是否解决了您的问题?