I'm trying to understand why a View
's background can be null and how that makes sense. Shouldn't there be at least be a default background (ie transparent) that is inherited from the parent view or something?
For example, the following TextView
's background attribute is omitted, which results in Background
(getBackground()
) being null
<TextView
android:id="@+id/null_bg_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!--android:background="@color/black"-->
TextView tv = v.FindViewById<TextView>(Resource.Id.null_bg_tv);
tv.Background.SetTintList(_csl); // null exception
Update
A comparison of object dumps show they only differed by a few fields
No background specified (android:background="@null")
Background=
HasOverlappingRendering=False
IsOpaque=False
android:background="@color/black"
Background=android.graphics.drawable.ColorDrawable@5c3246d
HasOverlappingRendering=True
IsOpaque=True
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…