【问题标题】:How to change string locale of notification bar in android如何在android中更改通知栏的字符串区域设置
【发布时间】:2018-07-17 05:37:14
【问题描述】:

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

我已使用以下代码更改上下文区域设置,但强制关闭后它不起作用

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 push-notification notifications android-notification-bar setlocale


【解决方案1】:

使用android.intent.action.CONFIGURATION_CHANGED

ACTION_CONFIGURATION_CHANGED

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

您无法通过清单中声明的​​组件接收此信息,只能通过 Context.registerReceiver() 显式注册。

这是一个受保护的意图,只能由系统发送。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2014-05-08
    相关资源
    最近更新 更多