
The most difficult stage in any business, perhaps, is the search for a starting point. When creating applications for android, this task has to be divided into several and determine, for example, for which versions of android the future application should be.
I will not breed demagogy and move on to the essence. To create, with your permission, a standard-template application (left slider menu, actionbar) that will look the same on both android-2.2 and android-4, I suggest not to reinvent the wheel and use ready-made
actionbar-sherlock and
sliding menu .
In this article, I will purposely omit the installation process of the development environment, but I will assume that the development is being done in
eclipse android sdk .
Training
- Download and import actionbar-sherlock and sliding-menu projects into the workspace.
- For the project sliding-menu, set the dependence on the actionbar-sherlock project.
When installing dependencies, you can pop up an error that jar files have different SHA. In this case, delete the android-support-v4.jar files from the sliding-menu project libs folder - Create a new project for your application, as usual. When installing, select the Minimum-Required-SDK as API8 (android-2.2) and the Target SDK which is required (API14 and higher). We set our project dependencies on actionbar-sherlock and sliding-menu projects.
It is possible that there will again be a conflict of jar files, as in the paragraph above. Then simply delete the file android-support-v4.jar in the libs folder from the project of your application.
Now almost everything is ready to create our application, but if you run the project on android-2.2 and android-4, you will see that the applications look completely different. To fix this, we will crank up a few simple manipulations:
- Create a folder in the res folder.
- From the drawable-mdpi folder, move the application's icon file (by default, eclipse calls it ic_launcher.png) to the drawable folder
- Remove the drawable-XXX folders and the values-XXX folders (my opinion that these folders should be created as needed and / or pre-release application preparation)
- In the res / values ​​/ styles.xml file, we indicate that the AppBaseTheme style will be inherited from the style / Theme.Sherlock.Light style
')
Salt itself
We are all set to create an application - we have the same look and feel of the application in the style of the 4th android and it all looks equally great on android-2.2.
At the moment, we lack only the side menu. To implement it, create a markup file in res / layout and name it, for example, sidemenu.xml. While we will not touch it.
Go to the main activity (if not created, create). Our activity will not be inherited from the standard activity class, but from the SherlockFragmentActivity class.
In the onCreate method, we describe the implementation of our side menu:
SlidingMenu menu = new SlidingMenu(this); menu.setMode(SlidingMenu.LEFT); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); menu.setFadeDegree(0.35f); menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); menu.setMenu(R.layout.sidemenu); menu.setBehindWidth(200); menu.setBackgroundColor(0xFF333333); getSupportActionBar().setHomeButtonEnabled(true);
After these actions, we have a blank ready to create an application that has a side menu (do not forget to add your markup to the res / layout / sidemenu.xml file), which opens / closes by snapping left / right, and our application also has the same look and feel for all versions of android. As a nice bonus, we also received a fully customizable actionbar (I will try to tell about it in the next post).
I will add an additional source of such a bogus project:
DownloadAs a result, the disc will look something like this:

Thank you all for your attention and pleasant development!
Useful links:
Android SDKActionBarSherlockSliding menuCreating a frame online (thanks
akira )
HoloEverywhere - Holo style for Android 2 and up
apps (thanks to
Dimmerg )
Side menu in the native way (thanks to
zserge )