How to set the part of the text view is clickable

后端 未结 20 980
无人共我
无人共我 2020-11-22 01:29

I have the text \"Android is a Software stack\". In this text i want to set the \"stack\" text is clickable. in the sense if you click on t

相关标签:
20条回答
  • 2020-11-22 02:33

    It really helpful for the clickable part for some portion of the text.

    The dot is a special character in the regular expression. If you want to spanable the dot need to escape dot as \\. instead of just passing "." to the spanable text method. Alternatively, you can also use the regular expression [.] to spanable the String by a dot in Java.

    0 讨论(0)
  • 2020-11-22 02:33

    To add a linked text in a text view, you can use the "footer_text" string resource example below and also edit your onCreate method for your activity, you can use the example below

    string.xml

    <?xml version="1.0" charset="utf-8"?>
    <resources>
         <string name="app_name">Name of My Application</string>
    
        <string name="footer_text">
            <a href="https://www.google.com/tos">Terms of Service</a>
            <a href="https://www.google.com/contact">Contact</a>
            <a href="https://www.google.com/privacy">Privacy Policy</a>
        </string>
    </resources>
    

    MainActivity.java

    ...
    
    @Override
    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);
        setContentView(R.layout.activity_main);
    
        TextView textView = findViewById(R.id.textViewLink);
        textView.setMovementMethod(LinkMovermentMethod.getInstance());
    }
    
    ....
    
    0 讨论(0)
提交回复
热议问题