android ClickableSpan intercepts the click event

前端 未结 5 985
慢半拍i
慢半拍i 2021-02-01 15:42

I have a TextView in a Layout. It\'s so simple. I put a OnClickListener in the layout and some part of the TextView is set to be ClickableSpan. I want the ClickableSpan to do s

5条回答
  •  深忆病人
    2021-02-01 16:37

    The easiest and fastest way to implement ClickableSpan is:

    new SmartClickableSpan
       .Builder(this)
       .regularText("I agree to all ")
       .clickableText(new ClickableOptions().setText("Terms of Use").setOnClick(new 
           ClickableSpan() {
               @Override
               public void onClick(@NonNull View view) {
                   // Your Code..
               }
       }))
       .into(myTextView);
    

    Adding regular Clickable Spans in Android requires calculating sizes for each clickable text, and when it comes to adding a lot of clickable and regular words or sentences in a TextView is becomes a mess.. By using SmartClickableSpan, you'll be able to add whatever amount of clickable words or sentences without any worries of calculating length of each text on every update on it.

    SmartClickableSpan Github:

    https://github.com/HseinNd98/SmartClickableSpan

提交回复
热议问题