【发布时间】:2021-03-02 19:50:37
【问题描述】:
我想使用国家/地区代码获取国家/地区代码,API 19 to API 28 的所有版本都应支持该代码。为此,我搜索了很多并找到了答案,然后我选择了标记为已接受答案的代码。
我正在使用该答案中的代码
private String localeToEmoji(Locale locale) {
String countryCode = locale.getCountry();
Log.v("Asdasdasdasd", countryCode+" ; "+locale.getDisplayCountry());
int firstLetter = Character.codePointAt(countryCode.toUpperCase(), 0) - 0x41 + 0x1F1E6;
int secondLetter = Character.codePointAt(countryCode.toUpperCase(), 1) - 0x41 + 0x1F1E6;
return new String(Character.toChars(firstLetter)) + new String(Character.toChars(secondLetter));
}
我正在使用这个功能,
Locale current = ConfigurationCompat.getLocales(getResources().getConfiguration()).get(0);
txt.setText(localeToEmoji(current));
但这不适用于Kitkat 和Lollipop。它只显示国家代码而不是国旗。我现在已经在这两种设备上进行了测试。
那么使用国家代码检索国旗的最佳方法是什么。
我们将不胜感激高级帮助!
【问题讨论】:
标签: android locale country-codes