Android Linkify both web and @mentions all in the same TextView

前端 未结 6 1405
半阙折子戏
半阙折子戏 2020-12-02 13:59

Ok so I asked this yesterday:

AutoLink @mentions in a twitter client

I got my @mentions linking correctly. But in order to get it to work I had to take andro

6条回答
  •  难免孤独
    2020-12-02 14:36

    use below code:

     TextView textView =  (TextView) findViewById(R.id.hello);
            String str = "@aman_vivek how are u  #aman_vivek  ";
            textView.setText(str);
            Pattern wikiWordMatcher = Pattern.compile("(@[a-zA-Z0-9_]+)");
            String wikiViewURL =    "http://www.twitter.com/";
            Linkify.addLinks(textView, wikiWordMatcher, wikiViewURL);
    
    
            Pattern wikiWordMatcher1 = Pattern.compile("\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
            Linkify.addLinks(textView, wikiWordMatcher1, null);
    

提交回复
热议问题