|
16 | 16 | package com.squareup.workflow1.ui |
17 | 17 |
|
18 | 18 | import android.content.Context |
| 19 | +import android.graphics.drawable.Drawable |
19 | 20 | import android.util.AttributeSet |
20 | 21 | import android.view.View |
21 | 22 | import android.view.ViewGroup |
@@ -121,6 +122,23 @@ class WorkflowViewStub @JvmOverloads constructor( |
121 | 122 | if (actual != this) actual.visibility = visibility |
122 | 123 | } |
123 | 124 |
|
| 125 | + /** |
| 126 | + * Sets the background of this stub as usual, and also that of [actual]. |
| 127 | + * Any new views created by [update] will be assigned this background. |
| 128 | + * |
| 129 | + * If the provided [background] is null, the background of [actual] will be left alone rather |
| 130 | + * than being nullified. |
| 131 | + */ |
| 132 | + override fun setBackground(background: Drawable?) { |
| 133 | + super.setBackground(background) |
| 134 | + // `actual` can be null here when setBackground() is called from the constructor, before |
| 135 | + // `actual` is really assigned to `this`. Thanks, Android! |
| 136 | + @Suppress("SENSELESS_COMPARISON") |
| 137 | + if (actual != this && actual != null && background != null) { |
| 138 | + actual.background = background |
| 139 | + } |
| 140 | + } |
| 141 | + |
124 | 142 | /** |
125 | 143 | * Replaces this view with one that can display [rendering]. If the receiver |
126 | 144 | * has already been replaced, updates the replacement if it [canShowRendering]. |
@@ -160,6 +178,7 @@ class WorkflowViewStub @JvmOverloads constructor( |
160 | 178 | .also { newView -> |
161 | 179 | if (inflatedId != NO_ID) newView.id = inflatedId |
162 | 180 | newView.visibility = visibility |
| 181 | + background?.let { newView.background = it } |
163 | 182 | replaceOldViewInParent(parent, newView) |
164 | 183 | actual = newView |
165 | 184 | } |
|
0 commit comments