Hello all I have just started Android development with the Eclipse IDE.
I am trying to produce a slide menu at the side together with an action bar at the top, similar to some popular applications such as 4Square, 9GAG, Facebook, etc.
I wish to use the Jeremy Feinstein sliding menu together with the Action Bar Sherlock libraries. I downloaded them from https://github.com/jfeinstein10/SlidingMenu and http://actionbarsherlock.com/download.html
I am currently learning how to use these libraries and tried to run the example provided in the zip file from GitHub. It took me days to correctly import the libraries and now there was no problem with the example.
But then when I tried to import the libraries into my own project, it seems that the project is referring to an incorrect R.java file. This is the code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.menu_frame);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new MenuListFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
} else {
mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
}
// customize the SlidingMenu
SlidingMenu sm = getSlidingMenu();
// these 3 lines containing errors:
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
The following error occurs for the 3 lines above
shadow_width cannot be resolved or is not a field
Also, for these lines,
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
return true;
}
The error is
main cannot be resolved or is not a field
==================================================================================
As for the way to import the two libraries, these are the steps I did, which I gathered from different sources and questions on the web:
Import the sliding menu library
File -> Import -> Android -> Existing Android Code Into Workspace
Browse -> SlidingMenu-master -> library -> Finish
Import the action bar sherlock library
File -> Import -> Android -> Existing Android Code Into Workspace
Browse -> JakeWharton-ActionBarSherlock-5a15d92 -> actionbarsherlock -> Finish
Set Action Bar Sherlock Properties
Project -> Properties -> Android -> Project Build Target -> Android 4.0.3
Set Sliding Menu Properties
Project -> Properties -> Android -> Project Build Target -> Android 4.0.3
Project -> Properties -> Android -> Library -> Add -> Add actionbarsherlock
Project -> Properties -> Project References -> check actionbarsherlock
Set My project Properties
Project -> Properties -> Android -> Project Build Target -> Android 4.0.3
Project -> Properties -> Android -> Library -> Add -> Add both libraries
Project -> Properties -> Project References -> check both libraries
In
library -> com.jeremyfeinstein.slidingmenu.lib.app -> SlidingActivity.java
and SlidingFragmentActivity.java
Change
extends SlidingActivity and SlidingFragmentActivity
Into
extends SherlockActivity and SherlockFragmentActivity
Delete
android-support-v4.jar
from my own project and actionbarsherlock, and for both of them, go to
Project -> Properties -> Java Build Path -> Libraries -> Add JARs
-> library (the slider menu library) -> libs -> android-support-v4.jar
Project Clean and restarted Eclipse
I an aware that I might have just made a very simple silly mistake, but any help is appreciated! Thanks!!
When you try to move the example's java file to your own project there are some other xml files that you might have left out. They are located in the res folder
The solution to the problem is either create your own xml files, or copy the example's xml files in the res folder, which are the following:
dimen.xml
drawable/shadow.xml
menu/main.xml