標題樣式是 ActionBar 樣式的一部分,因此要先定義 ActionBar 的樣式android
<style name="AppTheme" parent="AppBaseTheme"> <item name="android:actionBarStyle">@style/CustomActionBar</item> </style>
而後在 ActionBar 的樣式中經過 android:titleTextStyle 定義標題的樣式spa
<style name="CustomActionBar" parent="@android:style/Widget.DeviceDefault.ActionBar"> <item name="android:titleTextStyle">@style/ActionBarTitle</item> </style> <style name="ActionBarTitle" parent="@android:style/TextAppearance.Holo.Large"> <item name="android:textColor">@android:color/holo_blue_bright</item> <item name="android:textSize">20sp</item> </style>
副標題樣式一樣是 ActionBar 樣式的一部分,在ActionBar模式中經過 android:subtitleTextStyle 指定code
<style name="CustomActionBar" parent="@android:style/Widget.DeviceDefault.ActionBar"> <item name="android:titleTextStyle">@style/ActionBarTitle</item> <item name="android:subtitleTextStyle">@style/ActionBarSubtitle</item> </style> <style name="ActionBarSubtitle" parent="@android:style/TextAppearance.Holo.Medium"> <item name="android:textColor">@android:color/holo_blue_light</item> <item name="android:textSize">16sp</item> </style>
菜單文字的自定義直接經過 Activity 的 Theme 指定,而不是經過 ActionBar 的樣式blog
<style name="AppTheme" parent="AppBaseTheme"> <item name="android:actionBarStyle">@style/CustomActionBar</item> <item name="android:actionMenuTextAppearance">@style/ActionBarTitle</item> <item name="android:actionMenuTextColor">@android:color/holo_blue_light</item> </style> <style name="ActionBarMenu" parent="@android:style/TextAppearance.Holo.Large"> <item name="android:textColor">@android:color/holo_blue_light</item> <item name="android:textSize">20sp</item> </style>
有一點要注意,雖然經過 android:actionMenuTextApperance 指定的是 TextApperance,可是文字的顏色要經過 android:actionMenuTextColor 單獨指定get
<style name="TextAppearance.Holo.Widget.ActionBar.Title" parent="TextAppearance.Holo.Medium"> <item name="android:textSize">@android:dimen/action_bar_title_text_size</item> </style> <style name="TextAppearance.Holo.Widget.ActionBar.Subtitle" parent="TextAppearance.Holo.Small"> <item name="android:textSize">@android:dimen/action_bar_subtitle_text_size</item> </style> <style name="TextAppearance.Holo.Widget.ActionBar.Menu" parent="TextAppearance.Holo.Small"> <item name="android:textSize">12sp</item> <item name="android:textStyle">bold</item> <item name="android:textColor">?android:attr/actionMenuTextColor</item> <item name="android:textAllCaps">@android:bool/config_actionMenuItemAllCaps</item> </style>