I am implementing an application with fragments + main activity. The extended activity class is
android.app.Activity. I have aimed to use ActionBarSherlock to specialize the action bar. So, I have changed the inherited classes of main activity and fragment classes.
Old Version:
You also need to do more changes on libraries wher some classes are imported(e.g. Menu, MenuItem etc.) After all compatibility issues are solved, I have observed that navigation drawer menu didn't open by clicking ActionBarDrawerIcon. When inherited activity is android.app.Activity, it works normal. After some research, I have found what additional changes need to be done as difference:
There should be some lines need to be omitted and inserted inside onOptionsItemSelected function of the class which contains ActionBarDrawerToggle variables.
ActionBarDrawerToggle.onOptionsItemSelected(MenuItem item) requires android.view.MenuItem as parameter since it is under class which inherits SherlockFragment. So the parameter passed is in type of com.actionbarsherlock.view.MenuItem. Therefore, this method will not work and following lines need to be omitted:
As a final check, under MainActivity class, in onCreate() method, you may also need to add following lines:
android.app.Activity. I have aimed to use ActionBarSherlock to specialize the action bar. So, I have changed the inherited classes of main activity and fragment classes.
Old Version:
Main Activity -extends- Activity
Fragments -extends- Fragment
New Version:
Main Activity -extends- SherlockFragmentActivity
Fragments -extends- SherlockFragment
You also need to do more changes on libraries wher some classes are imported(e.g. Menu, MenuItem etc.) After all compatibility issues are solved, I have observed that navigation drawer menu didn't open by clicking ActionBarDrawerIcon. When inherited activity is android.app.Activity, it works normal. After some research, I have found what additional changes need to be done as difference:
There should be some lines need to be omitted and inserted inside onOptionsItemSelected function of the class which contains ActionBarDrawerToggle variables.
ActionBarDrawerToggle.onOptionsItemSelected(MenuItem item) requires android.view.MenuItem as parameter since it is under class which inherits SherlockFragment. So the parameter passed is in type of com.actionbarsherlock.view.MenuItem. Therefore, this method will not work and following lines need to be omitted:
- if (mDrawerToggle.onOptionsItemSelected(item)) {
- return true;
- }
As a replacement, add these lines under same method:
+ if ((item.getItemId() == android.R.id.home)) {
+ if (isDrawerOpen()) {
+ mDrawerLayout.closeDrawer(mFragmentContainerView);
+ } else {
+ mDrawerLayout.openDrawer(mFragmentContainerView);
+ }
+ }
As a final check, under MainActivity class, in onCreate() method, you may also need to add following lines:
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
After these additional insertions are done, synchronization of navigation drawer menu and ActionBarDrawerToggle has become as I expect. I didn't include all necessary code here, because there are enough examples on Internet. This was the issue I faced, therefore I have chosen to share specifically in which way I solved it. Have fun!
Comments
Post a Comment