gpt4 book ai didi

android - 如何在android中更改通知栏的字符串区域设置

转载 作者:太空狗 更新时间:2023-10-29 14:38:55 26 4
gpt4 key购买 nike

在我的应用程序中,我正在动态更改语言,所以如果我的语言在前台,通知语言会正确出现,但如果我强制关闭应用程序,通知会在设备区域设置中出现。

我使用下面的代码来更改上下文语言环境,但在强制关闭后它不起作用

fun wrapContext(context: Context?, locale: Locale): Context? {
if (context == null) return null

val configuration = context.resources.configuration
if (getSystemLocale(configuration) === locale) {
return context
}

setSystemLocale(configuration, locale)

val res = context.resources
res.updateConfiguration(configuration, res.displayMetrics)

return context.createConfigurationContext(configuration)
}

如有任何帮助,我们将不胜感激。

最佳答案

使用android.intent.action.CONFIGURATION_CHANGED

ACTION_CONFIGURATION_CHANGED

公共(public)静态最终字符串 ACTION_CONFIGURATION_CHANGED广播 Action :当前设备配置(方向、区域设置等)已更改。当发生这样的变化时,UI( View 层次结构)将需要根据这个新信息重建;在大多数情况下,应用程序不需要担心这一点,因为系统会负责停止和重新启动应用程序以确保它看到新的更改。一些无法重启的系统代码将需要监视这个 Action 并适本地处理它。

您不能通过 list 中声明的​​组件接收它,只能通过使用 Context.registerReceiver() 显式注册。

这是一个 protected Intent ,只能由系统发送。

关于android - 如何在android中更改通知栏的字符串区域设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51373909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com