creating a strikethrough text?

前端 未结 11 933
借酒劲吻你
借酒劲吻你 2020-11-30 17:36

Can I create a strikethrough text in Android, I mean adding a special value in the TextView tag that can make this possible?



        
11条回答
  •  佛祖请我去吃肉
    2020-11-30 18:26

    Paint.STRIKE_THRU_TEXT_FLAG

    TextView someTextView = (TextView) findViewById(R.id.some_text_view);
    someTextView.setText(someString);
    someTextView.setPaintFlags(someTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    

    For painting text, there are several bit flags for doing things like bold, italics, and yes strikethrough. So to enable the strikethrough, you need to flip the bit that corresponds to this flag. The easiest way to do this is to use a bitwise-or on the current flags and a constant that corresponds to a set of flags with only the strikethrough flag enabled.

    Edit from Comment by Ε Г И І И О :

    For any one wanting to remove this flag, this is how:

    someTextView.setPaintFlags(someTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
    

提交回复
热议问题