2014-01-27 121 views
0

With Android Studio我试图自定义我的选项卡Android操作栏样式生成器但这些更改未应用,我不知道为什么。我也遵循Android Developers的教程。我不知道如何继续。你能帮我吗?我一直试图这样做几个星期。 这是我styles.xml如何自定义ActionBar选项卡

<style name="Theme.Example" parent="@style/Theme.AppCompat.Light"> 
<item name="actionBarItemBackground">@drawable/selectable_background_example</item> 
<item name="popupMenuStyle">@style/PopupMenu.Example</item> 
<item name="dropDownListViewStyle">@style/DropDownListView.Example</item> 
<item name="actionBarTabStyle">@style/ActionBarTabStyle.Example</item> 
<item name="actionDropDownStyle">@style/DropDownNav.Example</item> 
<item name="actionBarStyle">@style/ActionBar.Solid.Example</item> 
<item name="actionModeBackground">@drawable/cab_background_top_example</item> 
<item name="actionModeSplitBackground">@drawable/cab_background_bottom_example</item> 
<item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example</item> 


</style> 

<style name="ActionBar.Solid.Example" parent="@style/Widget.AppCompat.Light.ActionBar.Solid"> 
<item name="background">@drawable/ab_solid_example</item> 
<item name="backgroundStacked">@drawable/ab_stacked_solid_example</item> 
<item name="backgroundSplit">@drawable/ab_bottom_solid_example</item> 
<item name="progressBarStyle">@style/ProgressBar.Example</item> 
</style> 

<style name="ActionBar.Transparent.Example" parent="@style/Widget.AppCompat.Light.ActionBar"> 
<item name="background">@drawable/ab_transparent_example</item> 
<item name="progressBarStyle">@style/ProgressBar.Example</item> 
</style> 

<style name="PopupMenu.Example" parent="@style/Widget.AppCompat.Light.PopupMenu"> 
<item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item> 
</style> 

<style name="DropDownListView.Example" parent="@style/Widget.AppCompat.Light.ListView.DropDown"> 
<item name="android:listSelector">@drawable/selectable_background_example</item> 
</style> 

<style name="ActionBarTabStyle.Example" parent="@style/Widget.AppCompat.Light.ActionBar.TabView"> 
<item name="android:background">@drawable/tab_indicator_ab_example</item> 
<item name="background">@drawable/tab_indicator_ab_example</item> 
</style> 

<style name="DropDownNav.Example" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar"> 
<item name="android:background">@drawable/spinner_background_ab_example</item> 
<item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item> 
<item name="android:dropDownSelector">@drawable/selectable_background_example</item> 
</style> 

<style name="ProgressBar.Example" parent="@style/Widget.AppCompat.ProgressBar.Horizontal"> 
<item name="android:progressDrawable">@drawable/progress_horizontal_example</item> 
</style> 

<style name="ActionButton.CloseMode.Example" parent="@style/Widget.AppCompat.Light.ActionButton.CloseMode"> 
<item name="android:background">@drawable/btn_cab_done_example</item> 
</style> 

<!-- this style is only referenced in a Light.DarkActionBar based theme --> 
<style name="Theme.Example.Widget" parent="@style/Theme.AppCompat"> 
<item name="popupMenuStyle">@style/PopupMenu.Example</item> 
<item name="dropDownListViewStyle">@style/DropDownListView.Example</item> 
</style> 

,这是我selector.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- Non focused states --> 
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" /> 
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_example" /> 
<!-- Focused states --> 
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_example" /> 
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_example" /> 
<!-- Pressed --> 
<!-- Non focused states --> 
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" /> 
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" /> 
<!-- Focused states --> 
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" /> 
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" /> 
</selector> 

(在结束所有我想要做的就是改变指示剂颜色好像是这样)

enter image description here

回答

1

你必须在你的清单中应用如下主题:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"> 

    ... 

    <application 
     android:theme="@style/Theme.Example"> <!-- Add the android:theme attribute to the application tag --> 

    .... 

EDIT

API> 14使用在它的android:命名空间在ActionBar,而COMPAT LIB不使用它。

values\styles.xml

<style name="Theme.Example" parent="@style/Theme.AppCompat.Light"> 
<item name="actionBarItemBackground">@drawable/selectable_background_example</item> 
<item name="popupMenuStyle">@style/PopupMenu.Example</item> 
<item name="dropDownListViewStyle">@style/DropDownListView.Example</item> 
<item name="actionBarTabStyle">@style/ActionBarTabStyle.Example</item> 
<item name="actionDropDownStyle">@style/DropDownNav.Example</item> 
<item name="actionBarStyle">@style/ActionBar.Solid.Example</item> 
<item name="actionModeBackground">@drawable/cab_background_top_example</item> 
<item name="actionModeSplitBackground">@drawable/cab_background_bottom_example</item> 
<item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example</item> 
</style> 

values-v14\styles.xml

<style name="Theme.Example" parent="@style/Theme.AppCompat.Light"> 
<item name="android:actionBarItemBackground">@drawable/selectable_background_example</item> 
<item name="android:popupMenuStyle">@style/PopupMenu.Example</item> 
<item name="android:dropDownListViewStyle">@style/DropDownListView.Example</item> 
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item> 
<item name="android:actionDropDownStyle">@style/DropDownNav.Example</item> 
<item name="android:actionBarStyle">@style/ActionBar.Solid.Example</item> 
<item name="android:actionModeBackground">@drawable/cab_background_top_example</item> 
<item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_example</item> 
<item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example</item> 
</style> 

values VS values-v14在Android开发者。

+0

我已经这样做了。我不知道为什么。在我看来没关系 – Pier

+0

在你运行Android的版本是什么? API> 14在其中使用了ActionBar的android名称空间,而Compat lib不使用它。请参阅http://developer.android.com/samples/ActionBarCompat-Styled/res/values/styles.html vs http://developer.android.com/samples/ActionBarCompat-Styled/res/values-v14/styles.html –

+0

终于有人回答我了!非常感谢你:) – Pier

相关问题