Reputation: 332
I'm implementing an app that uses "Side menu" like the FB Application.
The "Navigation Drawer" is customized for Applications that runs APIs > 11, and my app is intended to be used by any device, even if API < 11, So, I'm using the ActionBarSherloc
, and replaced the normal Menu
, MenuItem
, and MenuInflater
with Sherloc equivalents, and extended SherlocFragmentActivity
.
But for now, i still got an Error inside the "" method :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected((android.view.MenuItem) item)) {
return true;
}
// Handle action buttons
switch (item.getItemId()) {
case R.id.action_websearch:
// create intent to perform web search for this planet
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, getSupportActionBar()
.getTitle());
// catch event that there's no activity to handle intent
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(this, R.string.app_not_available,
Toast.LENGTH_LONG).show();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
In the "if-Statment"...
if (mDrawerToggle.onOptionsItemSelected((android.view.MenuItem) item)) {
return true;
}
if i used "(android.view.MenuItem) item)"...the method throws an exception for the type, and if i replaced it with "com.actionbarsherlock.view.MenuItem"...the method still got an Error of "The method onOptionsItemSelected(MenuItem) in the type ActionBarDrawerToggle is not applicable for the arguments (MenuItem)".
Any help..?! Thanks in advance,
Upvotes: 2
Views: 1909
Reputation: 10262
If you are using the support library, try using getSupportMenuInflater() and getSupportActionBar() instead of the regular methods.
Upvotes: 1
Reputation: 6705
ActionBarSherlock is a wrapper around the compatibility library that Android includes. You can certainly use ABS, as it simplifies handling of action bars, but it's not necessary for just doing a NavigationDrawer.
If you have the latest KitKat (sdk 19) look in your <SDK_HOME>/extras/android/support/v4/
folder there is a android-support-v4.jar
which contains among other things the appropriate DrawerLayout
for doing exactly what you want. If you include this library in your project you can run it fine.
This project demonstrates use of the NavigationDrawer without using ABS. You will have to make two changes to the Manifest to have it run on API v8.
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
Upvotes: 2