I'm trying to add a black view with 0.5 opacity over the item in a listview when the item is pressed.
I've tried several things like using selectors to change the background but it doesn't work because each item on the list is an image that fills the entire item, and the image is over the background.
I've also tried:
mWebcamsListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Log.i(TAG, "ITEM selected.");
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
Log.i(TAG, "Nothing selected.");
}
});
To change the opacity of the view but onItemSelected doesn't get triggered when I press the item, is there a way to get the view the user has pressed to change it's opacity?
List view:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Webcams"
android:background="@android:color/black">
<ListView
android:id="@+id/webcamsList"
android:layout_width="match_parent"
android:listSelector="@drawable/background_item_webcam"
android:layout_height="wrap_content" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="visible" />
Background I tried just to change the color to red:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@android:color/holo_red_dark"
/>
</shape>
The selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/background_index_webcam"/>
</selector>
EDIT: I added the selector code, I think it doesn't work because the image is over the background I reckon I need to add a layer over the image rather than change the background, or get the view programmatically and change it's alpha.
EDIT2: I found the solution, as I thought the color was changing on the background all I needed to do is set android:drawSelectorOnTop="true" to draw the selector on top of the item's view