handle textview link click in my android app

前端 未结 12 909
迷失自我
迷失自我 2020-11-22 04:33

I\'m currently rendering HTML input in a TextView like so:

tv.setText(Html.fromHtml(\"test\"));

The HTML b

12条回答
  •  渐次进展
    2020-11-22 05:13

    for who looks for more options here is a one

    // Set text within a `TextView`
    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText("Hey @sarah, where did @jim go? #lost");
    // Style clickable spans based on pattern
    new PatternEditableBuilder().
        addPattern(Pattern.compile("\\@(\\w+)"), Color.BLUE,
           new PatternEditableBuilder.SpannableClickedListener() {
            @Override
            public void onSpanClicked(String text) {
                Toast.makeText(MainActivity.this, "Clicked username: " + text,
                    Toast.LENGTH_SHORT).show();
            }
    }).into(textView);
    

    RESOURCE : CodePath

提交回复
热议问题