[Android] Action Bar Basic - With Android 2.x (v7 appcompat library)

  • 0
*Steps by Add ActionBar to Android 2.x (v7 appcompat library)

1. Download & add android-suuport-7v-appcompat
2. Fix YourActivityClass to extend ActionBarActivity
3. Add Appcompat Theme to AndroidManifest.xml
4. Use Custom Namespace for showAsAction Attribute
5. Run it!
6. [optional] onOptionsItemSelected, onCreateOptionsMenu

* Files
- res/menu/main.xml        // add menu items
- src/YourActivityClass.java
- AndroidManifest.xml

* Notice
- (7) Use Custom Namespace for showAsAction Attribute
xmlns:hmkcode="http://schemas.android.com/apk/res-auto" // 宣告 namespace (hmkcode)
hmkcode:showAsAction="always" // 使用 namespace (hmkcode)

This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. 
- Adding Action Buttons | Android Developers
Action Bar - Styling & Settings | Andro Tips

Reference
Android – ActionBarCompat 基本套用
Action Bar | Android Developer
Android – ActionBarCompat 基本套用
--
Android Action Bar Style Generator

沒有留言 :

張貼留言