Android canvas fill background color (Canvas application)

三世轮回 提交于 2019-12-03 14:39:26

Five questions. Let's see where I can help.

Q1: Tell the Paint to fill the rectangle: paint.setStyle(Paint.Style.FILL);

Q2: I see only the one view you create programmatically. Why would you like to count the views?

Q3: Again: One

Q4: You draw an mutable bitmaps by wrapping them with a Canvas. The method to actually draw are part of Canvas

Q5: The code you show is part of an Activity. The Activity is called by Android. It's your entry point into your App.

Thanks for the answer. I did the job of making the code for marked answer, and it works.

    Bitmap bg = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bg);
    // paint background with the trick
    Paint rect_paint = new Paint();
    rect_paint.setStyle(Paint.Style.FILL);
    rect_paint.setColor(Color.rgb(0, 0, 0));
    rect_paint.setAlpha(0x80); // optional
    canvas.drawRect(0, 0, width, height, rect_paint); // that's painting the whole canvas in the chosen color.

Q2:Hierarchy Viewer is very useful when you want to count how many views in your app. Optimizing Your UI

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!