正如我们在 https://stackoverflow.com/a/10144094/3286489 中看到的那样,我们可以通过 %1$d 等将参数添加到我们的字符串参数中。但我不知道如何在那里添加图像。
我们可以将图像添加到我们的字符串中,如我们在 https://stackoverflow.com/a/3177667/3286489 中看到的那样使用可跨越。但图片在文本中的位置需要明确说明。
所以我的问题是,有没有一种方法可以将我们的图像插入到 TextView 中(我可以使用 spannable),使用参数化方法作为 https://stackoverflow.com/a/10144094/3286489 ?
最佳答案
这是我之前做过的:
例如。您的字符串可能是:“这是一个 [img]”。
找到“[img]”的位置,替换为ImageSpan
编辑:正则表达式模式可能类似于
String message = "This is an [img]";
Pattern MY_PATTERN = Pattern.compile("\\[img\\]");
Matcher matcher = MY_PATTERN.matcher(message);
// Check all occurrences
while (matcher.find()) {
System.out.print("Start index: " + matcher.start());
System.out.print(" End index: " + matcher.end());
}
关于android - 是否可以使用字符串参数方法将 Image 插入到 TextView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37802527/