android - 我如何才能为我的 androidTest 提供本地化文本字符串
问题描述
我想要一些特定于语言的测试数据,并将它们放在特定值的 strings.xml 中-LANG 文件夹会是完美的,但我只希望这些测试数据可用于 androidTest 而不是主代码。这可以以某种方式完成吗?
谢谢索伦_
解决方案
您可以这样做并在运行测试后将其更改回来吗?
Resources res = context.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.setLocale(new Locale(language_code.toLowerCase())); // API 17+ only.
// Use conf.locale = new Locale(...) if targeting lower versions
res.updateConfiguration(conf, dm);
推荐阅读
- android - Android:具有不同元素大小、可调整大小、可拖动和水平分页的主屏幕
- r - How to loop over several models for survival analysis in R?
- python - 为什么我的 tkinter 窗口随着时间的推移变得越来越迟钝
- javascript - 传单默认控制框的Z-Index?
- sql - 如果第一个字段中有字母,SQL如何加入另一个字段
- try-catch - jq try .. catch 即使没有错误也直接去catch
- xamarin - 使用 Xamarin.Mac 根据本地化 CFBundleDisplayName 更改 AssemblyName
- c# - 模拟方法被调用,但验证返回 false
- python - 无法使用 AWS-Lambda 调用在 sagemaker 中创建的 XG-Boost 端点
- r - (优化)错误:(列表)对象不能被强制输入“双”