我应该使用哪个视图来显示仅包含背景颜色的小方块,以显示颜色预览?

Sol*_*ace 1 android android-view android-viewgroup

我想显示一种颜色供用户预览。View我应该使用哪个?

我想要一个小方块,比如说,100dp。

小智 5

通常要显示自定义图形,您会使用 aSurfaceView但在您的情况下,您可以只使用View.

xml:

<View android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@color/my_color"/>
Run Code Online (Sandbox Code Playgroud)

爪哇:

View view = new View(this);
view.setBackgroundColor(R.color.my_color);
Run Code Online (Sandbox Code Playgroud)