WhatsApp超链

我现在的效果

img


我期待的效果

img

img

你这需求都提到漂亮国的app了,🐂

Android APP下
在TextView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,以下代码示例:

   public class MainActivity extends Activity { 
        @Override 
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        } LinearLayout layout = new LinearLayout(this);
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 
        TextView textView = new TextView(this); 
        String html = "有问题:\n"; html+="<a href="http://www.baidu.com">百度一下</a>";
//注意这里必须加上协议号,即http://。 
//否则,系统会以为该链接是activity,而实际这个activity不存在,程序就崩溃。
         CharSequence charSequence = Html.fromHtml(html); 
        textView.setText(charSequence); textView.setMovementMethod(LinkMovementMethod.getInstance()); 
        layout.addView(textView); this.setContentView(layout,params); 
    }

第二种方式:

    public class MainActivity extends Activity {
        @Overrideprotected
        void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            LinearLayout layout = new LinearLayout(this);
            LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            TextView textView = new TextView(this);
            String html = "有问题:\n";
            html += "www.baidu.com";//这里即使不加协议好HTTP;也能自动被系统识别出来。 
            textView.setText(html);
            textView.setAutoLinkMask(Linkify.ALL);
            textView.setMovementMethod(LinkMovementMethod.getInstance());
            layout.addView(textView);
            this.setContentView(layout, params);
        }