Do I need to call back super.onDraw() in a custom view?

后端 未结 4 1927
情歌与酒
情歌与酒 2021-02-07 06:35

I\'m not too clear about this and neither are the docs.

When I\'m creating a custom view, I override like so:

@Override
public void onDraw(Canvas canvas)         


        
4条回答
  •  半阙折子戏
    2021-02-07 07:00

    Yes, it is. If you custom a TextView, the super.onDraw will ensure to draw whatever belongs to TextView attributes (like the text, text color, text shadow, etc...) The same with other Views like Button, CheckBox...

    In case your custom View extend View (not a specific subclass of View, just View), it is still better to leave super.onDraw(canvas) there for some View's draw methods (like setBackgroundDrawable, etc...)

提交回复
热议问题