📜 ⬆️ ⬇️

Simple Android app framework


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



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:


')
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: Download
As a result, the disc will look something like this:
image
Thank you all for your attention and pleasant development!

Useful links:
Android SDK
ActionBarSherlock
Sliding menu
Creating 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 )

Source: https://habr.com/ru/post/182780/


All Articles