標籤:
在Google官方Android設計指南中(連結:http://www.apkbus.com/design/get-started/ui-overview.html)有一個新特性就是自我標識,也就是宣傳自己,所以非常多應用如今也自然的使用ActionBar並提供自己的logo.
的應用:
Google的Android設計指南中是這樣說的:應用的 啟動表徵圖 作為啟動應用的入口是展示 logo 的最佳場所。你也能夠將啟動表徵圖放置在 操作欄 上,從而保證在應用內的全部頁面上都能看到它。
在使用ActionBar的時候。會發現一個問題。
在3.0曾經SDK中是不支援ActionBar的,所以假設手機apk要相容2.2或2.3的手機就須要用一個開源的項目ActionBarSherlock,詳細用法例如以下:
1、下載開源包:http://actionbarsherlock.com/usage.html
2、匯入到Eclipse中(和匯入項目步驟同樣,記得勾選Is Library)
3、在項目中引用(properties->android->add 加進去)
4、改動主題為@Style/Theme.Sherlock.Light(或其子類)
5、繼承SherlockActivity。
6、使用getSupportActionBar()擷取ActionBar對象。
上面方法就能夠實現低版本號碼使用ActionBar的問題。可是Goole去年推出了自己的相容包,使用起來更加方便。以下我們就來看看怎樣使用support_v7。
1、和上面一樣下載和匯入appcompat_7.x相容包(假設是官方最新的sdk開發工具則提供)
2、在項目中引用:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGF3YW5nYW5iYW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" />
3、改動主題為@style/Theme.AppCompat(或其子類)
4、改動menu/檔案夾下相應的xml檔案
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:alpha="http://schemas.android.com/apk/res-auto"> <!-- Search, should appear as action button --> <item android:id="@+id/action_search" android:icon="@drawable/ic_action_refresh" android:title="重新整理" alpha:showAsAction="always"/> <!-- Settings, should always be in the overflow --> <item android:id="@+id/action_add" android:title="分享" android:icon="@drawable/ic_action_share" alpha:showAsAction="always" /> <item android:id="@+id/action_settings" android:title="很多其它" android:icon="@drawable/ic_action_overflow" alpha:showAsAction="always"> <menu > <group > <item android:id="@+id/item1" android:title="個人中心" android:icon="@drawable/ic_action_share"/> <item android:id="@+id/item2" android:title="設定" android:icon="@drawable/ic_action_share"/> <item android:id="@+id/exit_system" android:title="退出" android:icon="@drawable/ic_action_share"/> </group> </menu> </item> </menu>
5、繼承自ActionBarActivity
6、使用getSupportActionBar擷取ActionBar對象。
ActionBar actionBar = getSupportActionBar();actionBar.setDisplayShowHomeEnabled(true);actionBar.setIcon(R.drawable.actionbar_icon);
在Android 2.2和2.3手機上完美執行...
Android菜鳥的成長筆記(28)——Google官方對Andoird 2.x提供的ActionBar支援