如何在TextView文本下划线并更改下划线的颜色 [英] How to under line a TextView text and change the color of the underline

查看:276
本文介绍了如何在TextView文本下划线并更改下划线的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本视图文本上加下划线并将下划线的颜色更改为蓝色.仅下划线.我们该怎么做.

I want to underline a text view text and change the color of the underline as blue.I have done that but my code is changing the color of the text view as well as the underline.I want to change the color of the underline only.How can we do this.

TextView tv = (TextView) findViewById(R.id.tv);
        SpannableString content = new SpannableString(tv.getText().toString());
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        content.setSpan(new ForegroundColorSpan(Color.BLUE), 0, content.length(), 0);
        tv.setText(content);

推荐答案

这应该对您有帮助

paint.setARGB(125,125,125,125);
paint.setflag(Paint.UNDERLINE_TEXT_FLAG);
textView.setPaintFlags( paint.getFlags());
textView.setText("UnderLined Text");

这篇关于如何在TextView文本下划线并更改下划线的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆