【问题标题】:Clickable every single separate word in TextView invoking a dialog containing selected word可单击 TextView 中的每个单独的单词,调用包含所选单词的对话框
【发布时间】:2014-07-28 23:36:38
【问题描述】:

我为那个可怕的标题道歉,但我想准确无误。

我在 LinearView 中有 ScrollView,并且我动态地创建了多行,其中填充了 TextView 的句子。 我设置了使用 SpannableText 创建的不同颜色,但我不知道如何使 TextView 的每个单词都以我想要的方式响应 - 弹出对话框问题,其中包含这个单词并问我想用它做什么。 我想将它移到下一个片段中的 EditText .. 只有那个..

请问,什么样的魔法最适合这个活动?并且也许是一个句子上的小例子。

【问题讨论】:

  • ClickableSpan 用于您要响应点击事件的字词。
  • 谢谢,我在“相关”问题的答案中找到了一个极好的解决方案。这个问题是here。我不知道的一件事是如何使文本再次变为红色或 .. 正常,就像添加该 onClick 事件之前一样..

标签: android textview clickable selectable


【解决方案1】:

您可以使用 Spannable 做更多事情,this blog post 拥有 Spannable 的一切,它应该能够帮助您。

如果您不想阅读整个博客,那么这里是简短的答案。

使用ForegroundColorSpan

SpannableString ss = new SpannableString("Color text");
ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);
ss.setSpan(span, 0, ss.length(), 0);

【讨论】:

    猜你喜欢
    • 2012-11-07
    • 2018-06-03
    • 2012-11-09
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多