如何在android中更改删除线的颜色? [英] How to change color of a strikethrough in android?
本文介绍了如何在android中更改删除线的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是安卓新手.我尝试使用以下代码进行删除线.但是我怎样才能改变删除线的颜色(目前是黑色,我想要红色).我知道它可能更简单,但即使在谷歌搜索之后我也找不到它.请帮忙.提前致谢.
I am new to android. I tried the below code for strikethrough. But how can I change the color of the strikethrough(currently it is BLACK, I want it RED). I know its probably simpler but I could not find it even after googling much. Please help.Thanks in advance.
txtview.setText("Hello");
txtview.setPaintFlags(txtview.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
推荐答案
我认为这对于简单的 textview 是不可能的,所以您必须执行以下操作:-
I think this is not possible for simple textview so you have to do the following:-
1.通过扩展View类创建自定义TextView
2.在 XML 布局中声明这个自定义文本视图,就像我们对 TextView 所做的一样.
最后编写一个 onDraw() 方法,如下所示.
And at last write an onDraw() method like following.
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(strikeThroughColor);
paint.setStyle(Paint.Style.FILL);
paint.setStrikeThruText(true);
paint.setStrokeWidth(strikeThroughWidth);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
super.onDraw(canvas);
float width = getWidth();
float heigh = getHeight();
canvas.drawLine(width/10, heigh/10, (width-width/10),(heigh-heigh/10), paint);
}
希望对你有帮助.
这篇关于如何在android中更改删除线的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文