【问题标题】:How can i concatenate using resource string with placeholders? [duplicate]如何使用资源字符串与占位符连接? [复制]
【发布时间】:2021-08-18 10:39:54
【问题描述】:

我有一个显示用户名的函数。它工作正常,但我收到此警告,我想知道如何解决它。

【问题讨论】:

    标签: android firebase kotlin


    【解决方案1】:

    在strings.xml 中定义字符串,不要在代码中硬编码。 “欢迎,%s”

    然后在代码中使用:

    getString(R.string.welcome_message).format(userProfile?.username)
    

    【讨论】:

      【解决方案2】:

      像这样声明你的字符串 Welcome %1$s 当你想使用它时

      context.getString(R.string.welcome,userProfile?.username)
      

      【讨论】:

        猜你喜欢
        • 2016-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-08
        • 2017-01-26
        • 2014-05-02
        • 2013-03-23
        相关资源
        最近更新 更多