設定ActionBar的樣式,是咱們必須掌握的技能,在以前咱們可能都須要一行一行的寫代碼,而後在模擬器上測試效果,可是如今咱們有個一個很棒的工具來設定樣式。設定ActionBar樣式的工做從未如此簡單過!html
http://romannurik.github.io/AndroidAssetStudio/index.htmlandroid
進入後咱們就能夠直接在可視化的界面中進行修改了,設定好後直接下載壓縮包。複製到res目錄下便可。最後要記得把Application或者Activity的主題修改成你作的主題名哦~ git
順便補充一個設置ActionBar背景的方法:github
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.id.icon));
下面是我這個主題的style:styles_mycompattheme.xml(這裏的文件是V14的,詳細的請下載源碼)express
<?xml version="1.0" encoding="utf-8"?> <!-- File created by the Android Action Bar Style Generator Copyright (C) 2011 The Android Open Source Project Copyright (C) 2012 readyState Software Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <resources> <style name="Theme.Mycompattheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="android:actionBarItemBackground">@drawable/selectable_background_mycompattheme</item> <item name="android:popupMenuStyle">@style/PopupMenu.Mycompattheme</item> <item name="android:dropDownListViewStyle">@style/DropDownListView.Mycompattheme</item> <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Mycompattheme</item> <item name="android:actionDropDownStyle">@style/DropDownNav.Mycompattheme</item> <item name="android:actionBarStyle">@style/ActionBar.Solid.Mycompattheme</item> <item name="android:actionModeBackground">@drawable/cab_background_top_mycompattheme</item> <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_mycompattheme</item> <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Mycompattheme</item> <!-- Light.DarkActionBar specific --> <item name="android:actionBarWidgetTheme">@style/Theme.Mycompattheme.Widget</item> </style> <style name="ActionBar.Solid.Mycompattheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <item name="android:background">@drawable/ab_background_textured_mycompattheme</item> <item name="android:backgroundStacked">@drawable/ab_stacked_solid_mycompattheme</item> <item name="android:backgroundSplit">@drawable/ab_background_textured_mycompattheme</item> <item name="android:progressBarStyle">@style/ProgressBar.Mycompattheme</item> </style> <style name="ActionBar.Transparent.Mycompattheme" parent="@style/Widget.AppCompat.ActionBar"> <item name="android:background">@drawable/ab_transparent_mycompattheme</item> <item name="android:progressBarStyle">@style/ProgressBar.Mycompattheme</item> </style> <!-- this style is only referenced in a Light.DarkActionBar based theme --> <style name="Theme.Mycompattheme.Widget" parent="@style/Theme.AppCompat"> <item name="android:popupMenuStyle">@style/PopupMenu.Mycompattheme</item> <item name="android:dropDownListViewStyle">@style/DropDownListView.Mycompattheme</item> </style> </resources>
固然,若是你以爲你想修改Menu和Tab上面的字體,設置個顏色什麼的。那麼下面的設置必定能夠知足你的須要。apache
更詳細的定義能夠參考:http://blog.csdn.net/gebitan505/article/details/12157027app
這裏定義了Tab中字體的大小和顏色,定義了Menu的字體的大小和顏色,定義了返回按鈕和分割欄的圖片。less
部分代碼以下,這個是在以前的代碼中修改的。ide
<style name="Theme.Mycompattheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <!-- 定義ActionBar左邊小箭頭的圖片 --> <item name="android:homeAsUpIndicator">@drawable/ic_search</item> <!-- 設置ActionBar的高度 --> <item name="android:actionBarSize">60dip</item> <!-- 設置Menu的顏色 --> <item name="android:actionMenuTextColor">#ff0000</item> <!-- 設置Menu的字體樣式 --> <item name="android:actionMenuTextAppearance">@style/MyMenuTextStyle</item> <!-- 設置ActionBar Tab字體的樣式 --> <item name="android:actionBarTabTextStyle">@style/MyTabTextStyle</item> <!-- 定義Tab之間的分割線的圖片 --> <item name="android:actionBarDivider">@drawable/ic_search</item>
省略了由工具生成的代碼……
</style> <!-- Menu的樣式 --> <style name="MyMenuTextStyle"> <item name="android:textSize">30sp</item> </style> <!-- Tab字體的顏色、字體等樣式 --> <style name="MyTabTextStyle" parent="@style/Widget.AppCompat.Light.ActionBar.TabText"> <item name="android:textColor">#0000ff</item> <item name="android:textSize">18sp</item> </style>
至於定義actionbar上面的進度條樣式的能夠看這篇文章:http://www.myexception.cn/mobile/1356045.html 工具
更加詳細全面的ActionBar的樣式的修改能夠看這裏:http://blog.csdn.net/guolin_blog/article/details/25466665 (推薦)