Hej伙计们,所以这是大约7年来我第一次找不到编程问题的答案,也没有接近问题所在的问题.
好吧,让我们从一开始就开始吧.我已经在Android SurfaceView上关注了一些教程和示例,以及如何在另一个线程中绘制其Canvas.到目前为止,没有问题,一切都像我期望的那样.我正在研究一个场景,我在SurfaceView周围有一些填充,这意味着父视图的背景(一个FrameLayout)呈现在前面提到的SurfaceView周围.事情变得有趣,因为我使用与父背景相同的颜色来清除SurfaceView的Canvas.
root(= parent)FrameLayout在主题中设置了背景
< item name =“android:windowBackground”> @ color / palette_primary_dark< / item>
这在colors.xml中定义
< color name =“palette_primary_dark”>#28252C< / color>
在我的线程构造函数中,我将相同的颜色检索到全局变量mClearColor中
mClearColor = ContextCompat.getColor(context,R.color.palette_primary_dark);
上下文是我从SurfaceView收到的上下文.
以下代码是在我的线程中运行的渲染循环
@Override
public void run() {
while (mShouldRun) {
Canvas canvas = null;
try {
canvas = mSurfaceHolder.lockCanvas();
synchronized