3

I want to display a color for the user to preview. Which View should I use?

I want a small square of, say, 100dp.

Solace
  • 8,612
  • 22
  • 95
  • 183

2 Answers2

8

Normally to display custom graphics you would use a SurfaceView but in your case you can just use a View.

xml:

<View android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@color/my_color"/>

Java:

View view = new View(this);
view.setBackgroundColor(R.color.my_color);
TomTsagk
  • 1,474
  • 9
  • 23
1

If you want to display only color then you can also set it as background color of your layout and if you want view then simply use the View of andorid SDK.

In both case use simple line of code in main_layout1.xml of layout or view as you suits

 android:background="@color/my_color"
Androider
  • 3,833
  • 2
  • 14
  • 24