Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
When trying to change the selector for a ListView programmatically to any color I want, I discovered that I am unable to make my own drawable in code.
When looking at the definition for the Android AbsListView in Xamarin, the method SetSelector(Drawable drawable) that is referenced https://developer.android.com/reference/android/widget/AbsListView.html#setSelector(android.graphics.drawable.Drawable) is not available.
I believe it should be.
Thank you for the report. This is one of the cases where we provide the int method and not the Drawable method.
For example, you won't see this method in the following documentation:
The only method you'll find is the following:
There are many ways to workaround this by using the Int32 method, but it would be nicer to have a Drawable one exposed. Thus I am marking this issue as CONFIRMED.
Use the Resources.GetIdentifier method to get the respective identifier of the item, or use the Resource.drawable.resourcename
Now that this bug is CONFIRMED, we will get some Android Engineering eyes on it. Thanks again for the report!
My main problem is that I cannot use a programmatically created drawable, so I have to have something premade in the XML. That is not always the case, especially for Forms projects, where I am looking to use this.
Just looking to touch base on this again.
Any idea when we might get around to this? Just want to know if its pretty low priority or we might see it before the bug gets lost to me.
You should still be able to workaround this with the respective int32 constructor. There are many ways to get the identifier for your XML views as mentioned previously.
This bug does have a workaround and thus a normal priority.
I am a tad confused as to the workaround described.
Are we saying the best workaround to allowing my listview to be any color I want for the selector is to make Resources for them? If I had 15 options I wanted to allow, I would need something in the Resources.xml for each?
I was assuming that the method I referenced would allow me to set any drawable, even a programmatically generated one, which is my goal here.
After looking into this further, I believe this is not actually missing. Rather it is exposed differently via the .Selector property which takes in a Drawable.
You would thus say something like:
ListView list = new ListView(this);
list.Selector = Drawable.CreateFromPath("MyPath");
Thus I am marking this bugzilla answered as we tend to use properties over methods to follow C# convention. You can read more on this here:
Please let me know if this solves your problem.
Hmmm.. I was sure I had tried that before and there was no setter. Maybe I am just blind.
Oh well, there is a way to do what I want. That's what matters. Thanks.