ActionBar样式修改

来源:互联网 发布:mac如何添加照片 编辑:程序博客网 时间:2024/05/16 23:50

更多请阅读 http://android-developers.blogspot.com/2011/04/customizing-action-bar.html


定义文本颜色,包括Title,Tab,Menu的文本颜色

<?xml version="1.0" encoding="utf-8"?><resources>    <!-- the theme applied to the application or activity -->    <style name="CustomActionBarTheme" parent="@style/Theme.Holo">        <item name="android:actionBarStyle">@style/MyActionBar</item>        <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>        <item name="android:actionMenuTextColor">@color/actionbar_text</item>    </style>    <!-- ActionBar styles -->    <style name="MyActionBar" parent="@style/Widget.Holo.ActionBar">        <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>    </style>    <!-- ActionBar title text -->    <style name="MyActionBarTitleText" parent="@style/TextAppearance.Holo.Widget.ActionBar.Title">        <item name="android:textColor">@color/actionbar_text</item>    </style>    <!-- ActionBar tabs text styles -->    <style name="MyActionBarTabText" parent="@style/Widget.Holo.ActionBar.TabText">        <item name="android:textColor">@color/actionbar_text</item>    </style></resources>

定义ActionBar的颜色

<resources xmlns:android="http://schemas.android.com/apk/res/android">    <style name="AppBaseTheme_Day" parent="android:Theme.Holo.Light"></style>    <style name="AppTheme_Day" parent="AppBaseTheme_Day">        <item name="android:actionBarStyle">@style/ActionbarStyle</item>    </style>     <!-- define action style -->    <style name="ActionbarStyle" parent="android:Widget.Holo.ActionBar">        <item name="android:background">@drawable/actionbar_bg</item>        <!-- split action bar -->        <item name="android:backgroundSplit">@drawable/actionbar_bg</item>         <!-- navigation tabs -->        <item name="android:backgroundStacked">@drawable/actionbar_bg</item>     </style></resources>



定义OverFlowMenu,Tab,NavigationList,OverFlowButton的样式

<?xml version="1.0" encoding="utf-8"?><resources><!-- Base application theme is the default theme. --><style name="Theme" parent="android:Theme"></style><style name="Theme.AndroidDevelopers" parent="android:style/Theme.Holo.Light"><item name="android:selectableItemBackground">@drawable/ad_selectable_background</item><item name="android:popupMenuStyle">@style/MyPopupMenu</item><item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>        <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>        <item name="android:actionDropDownStyle">@style/MyDropDownNav</item>        <item name="android:listChoiceIndicatorMultiple">@drawable/ad_btn_check_holo_light</item>        <item name="android:listChoiceIndicatorSingle">@drawable/ad_btn_radio_holo_light</item><item name="android:actionOverflowButtonStyle">@style/MyOverflowButton</item></style><!-- style the overflow menu --><style name="MyPopupMenu" parent="android:style/Widget.Holo.Light.ListPopupWindow"><item name="android:popupBackground">@drawable/ad_menu_dropdown_panel_holo_light</item></style><!-- style the items within the overflow menu --><style name="MyDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown"><item name="android:listSelector">@drawable/ad_selectable_background</item></style>    <!-- style for the tabs -->    <style name="MyActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBarView_TabView">        <item name="android:background">@drawable/actionbar_tab_bg</item>        <item name="android:paddingLeft">32dp</item>        <item name="android:paddingRight">32dp</item>    </style><!-- style the list navigation --><style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner.DropDown.ActionBar"><item name="android:background">@drawable/ad_spinner_background_holo_light</item><item name="android:popupBackground">@drawable/ad_menu_dropdown_panel_holo_light</item><item name="android:dropDownSelector">@drawable/ad_selectable_background</item></style><!-- the following can be used to style the overflow menu button only do this if you have an *extremely* good reason to!! --><!--<style name="MyOverflowButton" parent="@android:style/Widget.Holo.ActionButton.Overflow"><item name="android:src">@android:drawable/ic_menu_view</item><item name="android:background">@drawable/action_button_background</item></style>--></resources>


1------actionbar_tab_bg.xml,用于tab的背景修改。曾一度认为只需在系统tab的基础上修改一下颜色即可,其实不然。需另外弄几张图片,(如我想把tab改成红色背景,那么我就要找几张红色背景的图片)。

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/ad_tab_unselected_holo" />    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/ad_tab_selected_holo" />    <item android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/ad_tab_selected_pressed_holo" />    <item android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/ad_tab_selected_pressed_holo" /></selector>
2------ad_action_bar_gradient_bak.xml,用于actionbar的颜色渐变,本例是从顶到底颜色逐渐变浅。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">    <gradient        android:startColor="@color/honeycombish_blue"        android:endColor="@color/background"        android:type="linear"        android:angle="270" /></shape>
3------ad_btn_check_holo_light.xml,用于单选背景的变换。

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><!-- Enabled states --><item android:state_checked="true" android:state_window_focused="false"android:state_enabled="true" android:drawable="@drawable/btn_check_on_holo_light" /><item android:state_checked="false" android:state_window_focused="false"android:state_enabled="true" android:drawable="@drawable/btn_check_off_holo_light" /><item android:state_checked="true" android:state_pressed="true"android:state_enabled="true" android:drawable="@drawable/ad_btn_check_on_pressed_holo_light" /><item android:state_checked="false" android:state_pressed="true"android:state_enabled="true" android:drawable="@drawable/ad_btn_check_off_pressed_holo_light" /><!-- ignoring focused states for brevity <item android:state_checked="true" android:state_focused="true"android:state_enabled="true" android:drawable="@drawable/btn_check_on_focused_holo_light" /><item android:state_checked="false" android:state_focused="true"android:state_enabled="true" android:drawable="@drawable/btn_check_off_focused_holo_light" />--><item android:state_checked="false" android:state_enabled="true"android:drawable="@drawable/btn_check_off_holo_light" /><item android:state_checked="true" android:state_enabled="true"android:drawable="@drawable/btn_check_on_holo_light" /><!-- ignoring disabled states for brevity<item android:state_checked="true" android:state_window_focused="false"android:drawable="@drawable/btn_check_on_disabled_holo_light" /><item android:state_checked="false" android:state_window_focused="false"android:drawable="@drawable/btn_check_off_disabled_holo_light" /><item android:state_checked="true" android:state_focused="true"android:drawable="@drawable/btn_check_on_disabled_focused_holo_light" /><item android:state_checked="false" android:state_focused="true"android:drawable="@drawable/btn_check_off_disabled_focused_holo_light" /><item android:state_checked="false"android:drawable="@drawable/btn_check_off_disabled_holo_light" /><item android:state_checked="true"android:drawable="@drawable/btn_check_on_disabled_holo_light" /> --> </selector>
4------ad_btn_radio_holo_light.xml,用于多选背景的变换。

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><!-- Enabled states --><item android:state_checked="true" android:state_window_focused="false"android:state_enabled="true" android:drawable="@drawable/btn_radio_on_holo_light" /><item android:state_checked="false" android:state_window_focused="false"android:state_enabled="true" android:drawable="@drawable/btn_radio_off_holo_light" /><item android:state_checked="true" android:state_pressed="true"android:state_enabled="true" android:drawable="@drawable/ad_btn_radio_on_pressed_holo_light" /><item android:state_checked="false" android:state_pressed="true"android:state_enabled="true" android:drawable="@drawable/ad_btn_radio_off_pressed_holo_light" /><!-- ignoring focused states for brevity <item android:state_checked="true" android:state_focused="true"android:state_enabled="true" android:drawable="@drawable/btn_radio_on_focused_holo_light" /><item android:state_checked="false" android:state_focused="true"android:state_enabled="true" android:drawable="@drawable/btn_radio_off_focused_holo_light" />--><item android:state_checked="false" android:state_enabled="true"android:drawable="@drawable/btn_radio_off_holo_light" /><item android:state_checked="true" android:state_enabled="true"android:drawable="@drawable/btn_radio_on_holo_light" /><!-- ignoring disabled states for brevity<item android:state_checked="true" android:state_window_focused="false"android:drawable="@drawable/btn_radio_on_disabled_holo_light" /><item android:state_checked="false" android:state_window_focused="false"android:drawable="@drawable/btn_radio_off_disabled_holo_light" /><item android:state_checked="true" android:state_focused="true"android:drawable="@drawable/btn_radio_on_disabled_focused_holo_light" /><item android:state_checked="false" android:state_focused="true"android:drawable="@drawable/btn_radio_off_disabled_focused_holo_light" /><item android:state_checked="false"android:drawable="@drawable/btn_radio_off_disabled_holo_light" /><item android:state_checked="true"android:drawable="@drawable/btn_radio_on_disabled_holo_light" />--></selector>
5------ad_btn_radio_holo_light.xml,用于item背景的变换,未选中时为透明,选中未绿色。

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"  android:exitFadeDuration="@android:integer/config_mediumAnimTime" ><item android:state_pressed="true" android:drawable="@drawable/selected_background" /><item android:drawable="@android:color/transparent" /></selector>
6------ad_spinner_background_holo_light.xml,用于下拉列表背景的变换。

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_enabled="false"          android:drawable="@drawable/spinner_disabled_holo_light" />    <item android:state_pressed="true"          android:drawable="@drawable/ad_spinner_pressed_holo_light" />    <item android:state_pressed="false" android:state_focused="true"          android:drawable="@drawable/ad_spinner_focused_holo_light" />    <item android:drawable="@drawable/spinner_default_holo_light" /></selector>







0 0
原创粉丝点击