如何改变在Android中删除线的颜色? [英] How to change color of a strikethrough in android?

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

问题描述

我是新来的机器人。我想下面的$ C $下删除线。但我怎么能更改删除线的颜色(目前它是黑色的,我想它RED)。我知道它可能是简单,但我甚至很多谷歌上搜索后无法找到它。事先请help.Thanks。

  txtview.setText(你好);
txtview.setPaintFlags(txtview.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG);
 

解决方案

我觉得这是不可能的简单的的TextView ,所以你必须做到以下几点: -

1,创建通过扩展视图类自定义的TextView

里面的XML布局 2.Declare这个自定义的TextView同样喜欢我们做的TextView。

和最后写的的OnDraw()方式类似以下。

  @覆盖
       保护无效的OnDraw(帆布油画){
        涂料粉刷=新的油漆();
        paint.setColor(strikeThroughColor);
        paint.setStyle(Paint.Style.FILL);
        paint.setStrikeThruText(真正的);
        paint.setStrokeWidth(strikeThroughWidth);
        paint.setFlags(Paint.ANTI_ALIAS_FLAG);
        super.onDraw(画布);
        浮动宽度=的getWidth();
        浮唤起注意=的getHeight();
        canvas.drawLine(宽度/ 10,唤起注意/ 10,(宽度宽/ 10),(唤起注意-唤起注意/ 10),漆);
}
 

希望它会帮助你。

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);

解决方案

I think this is not possible for simple textview so you have to do the following:-

1.Create a custom TextView by extending View class

2.Declare this custom textview inside XML layout same like we do for TextView.

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);
}

Hope it will helps you.

这篇关于如何改变在Android中删除线的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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