如何在Android偏好中转义'%'

Luk*_*kap 2 xml string android android-preferences

我已经阅读了这个线程FATAL EXCEPTION主要Android应用程序,它是非常有帮助的.

是的,这很好用

<string formatted="false">some text and % in the text</string>
Run Code Online (Sandbox Code Playgroud)

所以如果有人使用xml格式化的="false"就是解决方案.

但我的代码有问题

getPreferenceScreen().findPreference("my_key").setSummary("some text and % in the text"));
Run Code Online (Sandbox Code Playgroud)

这有一个例外,有谁知道如何逃脱%?

因此,当调用String.format()时,%将被视为'%'而不是特殊字符

谢谢

小智 6

加倍吧!而不是使用百分之一,使用两个.像这样.

setSummary("some text and %% in the text")
Run Code Online (Sandbox Code Playgroud)

  • 这有效但不复杂,如果有人有这种问题需要检查构建版本,如果少于14(冰淇淋三明治)然后使用"%"如果是冰淇淋或冰淇淋后的东西然后使用" %%",我希望这会对某人有所帮助 (4认同)