Bug 26381 - Expose support resources such as android.support.v7.appcompat.R.id.search_plate
Summary: Expose support resources such as android.support.v7.appcompat.R.id.search_plate
Status: RESOLVED FIXED
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Production (addons.xamarin.com)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2015-01-24 06:38 UTC by Dimitar Dobrev
Modified: 2015-12-21 20:57 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:
Status:
RESOLVED FIXED

Description Dimitar Dobrev 2015-01-24 06:38:23 UTC
These resources are available to Java (http://stackoverflow.com/a/21291092) but not to C#. As a result, when using android.support.v7.widget.SearchView, I am forced to do this:

// obtain the id by inspecting the visual tree of the search view in the debugger
int searchPlateId = 2131427382;
View searchPlate = searchView.FindViewById(searchPlateId);

I am sure there's no need to explain why this is a horrible "solution". I am aware of this approach:

int searchPlateId = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);

but for some reason it only returns a correct id for the regular (non-support) SearchView.
Comment 1 Dimitar Dobrev 2015-01-24 06:40:21 UTC
I am going to try some Java reflection in order to get to android.support.v7.appcompat.R.id.search_plate but even if I make it it will still be ugly so the issue remains.
Comment 2 Dimitar Dobrev 2015-01-24 10:24:13 UTC
The following code:

var id = Class.ForName("android.support.v7.appcompat.R$id");
int searchPlateId = (int) id.GetField("search_plate").Get(id);
int searchSrcTextId = (int) id.GetField("search_src_text").Get(id);

works. As you know, Class.getField only retrieves public fields (unlike getDeclaredField) which is further proof that the class should be accessible through C#.
Comment 3 Jonathan Pryor 2015-01-27 16:09:57 UTC
Xamarin.Android 4.x includes an ancient version of the Android support library. Xamarin.Android 5.0 no longer includes the binding; you should instead use the Android Support Component:

https://components.xamarin.com/view/xamandroidsupportv7appcompat

The component doesn't appear to provide that member either. Let's see if they have any ideas...
Comment 4 David Humphreys 2015-12-21 20:57:55 UTC
The component includes the SearchView class since version 20.0.0.1