I assume that using reflection is the answer, but I can't understand the syntax, no matter how hard I read.
Perhaps you can use reflection. I would not.
I would go with HoneycombHelper .
This sample project also has a situation where it needs to do different things for version 3.0 versus no - in this case, work with the custom View in the action bar. You cannot call getActionView() on MenuItem pre-3.0.
So where I need a custom View , I do this:
EditText add=null; if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) { View v=HoneycombHelper.getAddActionView(menu); if (v!=null) { add=(EditText)v.findViewById(R.id.title); } } if (add!=null) { add.setOnEditorActionListener(onSearch); }
Here I buried the call to getActionView() in the static method of the HoneycombHelper class:
class HoneycombHelper { static View getAddActionView(Menu menu) { return(menu.findItem(R.id.add).getActionView()); } }
I only download HoneycombHelper in version 3.0 or higher, so even though it contains invalid method calls for older versions of Android, this is not a problem.
In your case, your HoneycombHelper will have a gimmeMyBuilderDammit() method or some that uses the level 11 API constructor.
source share