Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay a color over a view

For a custom AdapterView implementation I'd like to add a color overlay to selected items. How do I add a color overlay to a child of my AdapterView?

like image 448
multiholle Avatar asked Nov 13 '13 12:11

multiholle


1 Answers

If you are using your own layout simply change the container to RelativeLayout (or a Layout class that inherits from RelativeLayout), and put the color overlay after the main layout. All you need is to add a View and set it's background and alpha. alpha set to the value 1 will activate this overlay, whereas setting alpha to 0 will go back to normal.

Example:

<RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <!-- add your views here -->

  <View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#8000FF00" />

</RelativeLayout>

This will overlay a green layer with 50% alpha over the other views which are before it in the layout.

like image 105
pshegger Avatar answered Nov 14 '22 23:11

pshegger