Is it possible to change the background color on long press (Context Menu ) in Xamarin Forms in android ?
I have have tried customizing the theme but it doesn't work or maybe I am wrong somewhere !
yes it is possible. But the process of achieving it is quite complex I think. You need to add gesture recognizer to your listview items. Usually what I do is have a boxview or some sort of frame that covers up the background of each listview item and then handle color of that boxview whenever a listview item is tapped. Hope this points you to the right direction
I'm not sure but my guess is ListView context menu is tied up with the listview item itself. But if you add gesture recognizer to something inside the listview (say boxview) then it should trigger both. if not it will definitely trigger your boxview implementation and you can invoke the context menu for that particular item.
@AdamMeaney said:
As a note, in case you meant the actual context menu bar at the top and not the listview item that was clicked, there are themes for that too.
Answers
yes it is possible. But the process of achieving it is quite complex I think. You need to add gesture recognizer to your listview items. Usually what I do is have a boxview or some sort of frame that covers up the background of each listview item and then handle color of that boxview whenever a listview item is tapped. Hope this points you to the right direction
@NishantJha The issue is in long press scenario which fires up menu context menu items.
I was giving you an example. I have not implemented long tap, I have only done tap. However, gesture recognizer also includes long press as option.
@NishantJha Yes it includes but it wont fire up menu context ,right ?
I'm not sure but my guess is ListView context menu is tied up with the listview item itself. But if you add gesture recognizer to something inside the listview (say boxview) then it should trigger both. if not it will definitely trigger your boxview implementation and you can invoke the context menu for that particular item.
For our application, changing the theme attributes took care of this.
These are what we have set. Take what you need.
I am saying that's how I would approach it. If I had an implementation I would have given you the code but I don't.
@AdamMeaney I would give it a try
As a note, in case you meant the actual context menu bar at the top and not the listview item that was clicked, there are themes for that too.
In your AppTheme, add these lines:
@ASHISHKUMAR.8068 have you found the solution?
Works for me, but I had to change a little, the name "accentColor" to "colorAccent" (this came from colors.xml)
@AdamMeaney It's working fine, thanks.