handle textview link click in my android app

前端 未结 12 1178
迷失自我
迷失自我 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 04:56

    I changed the TextView's color to blue by using for example:

    android:textColor="#3399FF"
    

    in the xml file. How to make it underlined is explained here.

    Then use its onClick property to specify a method (I'm guessing you could call setOnClickListener(this) as another way), e.g.:

    myTextView.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        doSomething();
    }
    });
    

    In that method, I can do whatever I want as normal, such as launch an intent. Note that you still have to do the normal myTextView.setMovementMethod(LinkMovementMethod.getInstance()); thing, like in your acitivity's onCreate() method.

提交回复
热议问题