Android active link of url in TextView

前端 未结 10 528
盖世英雄少女心
盖世英雄少女心 2020-11-30 22:24

I have getting dynamic text from a web service and showing the same in a TextView. Sometimes the TextView has url like hello

10条回答
  •  执念已碎
    2020-11-30 22:52

    Add these lines of code to your textView in xml File it will work perfectly fine..

    android:autoLink="web" android:textColorLink="@android:color/holo_orange_dark" android:linksClickable="true"

    or if want a your own link in textview add these lines of code in your java file

      final SpannableString s = new SpannableString("https://play.google.com/store/apps/details?id=cn.wps.moffice_eng");
      Linkify.addLinks(s, Linkify.ALL);
    

    set this 's' String in your TextView by function

    Textview.setText(s);
    

    and don't forget to add this line

     ((TextView)findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    

    id will be your textview id

    Enjoy ...

提交回复
热议问题