This post shows by example the steps that are necessary for migrating an android application from Actionbarsherlock to Material Design (introduced in android KitKat/Version 5.x/API level 21/22), while keeping compatibility with at least android Gingerbread/Version 2.3 /API level 9). It uses the appcompat-v7 library on API level 22. The app that was migrated (nusic) in this example is developed using Eclipse, Maven and RoboGuice.
Before-after comparison
Let’s begin with some before-after screenshots:
Basic migration (appcompat-v7)
The following lists the steps that were implemented in order to change the app as depicted in the screenshots above.
- Update Android SDK Tools
- Eclipse
- Setup Eclipse project for appcompat described here.
- Link your project with it. Right click on your project |
Properties
|Android
|Library
|Add
- Remove action bar sherlock. Same menu as above.
- Set Up Maven Build
-
<repositories> <repository> <id>android</id> <url>file://${env.ANDROID_HOME}/extras/android/m2repository</url> </repository> </repositories>
-
<dependency> <groupId>com.android.support</groupId> <artifactId>appcompat-v7</artifactId> <version>${android.compatibility-v7.version}</version> <type>aar</type> </dependency>
-
- Migrate from Actionbarsherlock to appcompat
styles.xml
<!-- <style name="AppBaseTheme" parent="@style/Theme.Sherlock"> --> <style name="AppBaseTheme" parent="@style/Theme.AppCompat">
- Replacing classes
RoboSherlockFragment
->RoboFragment
RoboSherlockFragmentActivity
->RoboActionBarActivity
RoboSherlockPreferenceActivity
-> Write your ownRoboAppCompatPreferenceActivity
that looks like this (or as described here) but is derived fromRoboPreferenceActivity
(
see here for the class that was used in the example).
Then derive your class from it as before withRoboSherlockPreferenceActivity
.
- Replacing methods
getSherlockActivity()
->getActivity()
getSupportMenuInflater()
->getMenuInflater()
- Fixing imports
android.view.Menu
android.support.v7.app.ActionBar
- Updating
proguard.cfg
- Remove actionbarsherlock
- Add
# support4, appcompat-v7, design support -dontwarn android.support.** -keep class android.support.** { *; } -keep interface android.support.** { *; }
For further info please see
- The second post of this series about android UI modernization that contains the desing support library, switches and recommendations for action buttons.
- The commits that applied these steps to nusic (457a50bfcd63d084dac0faf3f35efe3f8077fb7e and b1ea9f80cb2bb4cdc57de0bdcf29e7e4a47b7289)
- Migrating from ActionBarSherlock to ActionBarCompat | Grokking Android
- AppCompat v21 — Material Design for Pre-Lollipop Devices! | Android Developers Blog
Reblogged this on Dinesh Ram Kali..