Coloring the Space widget

Malwinder Singh picture Malwinder Singh · Jan 24, 2016 · Viewed 11.2k times · Source

I am trying to color the Space widget. I tried using both the android:foreground and android:background attributes, but still it is displaying a transparent View.

 <android.support.v4.widget.Space
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:foreground="@android:color/black"
    android:background="@android:color/black" />

Answer

Phant&#244;maxx picture Phantômaxx · Jan 24, 2016

As per the official docs definition:

Space is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.

They probably didn't think of "coloring an empty space".
Where "empty" means "without color", "invisible".

That's what I'd do:

<View
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@android:color/black"
/>

Using a bare View as a divider is one of my 2/3 favourite tricks with bare Views.
I also use them as spacers and as "center point" in RelativeLayouts.