我的操作栏中有一个导航列表,背景为深色.然而,弹出菜单具有白色背景.
所以我想要实现的是,操作栏内的项目文本颜色是白色,而菜单弹出的项目文本颜色是黑色.
这是我到目前为止的两个例子:
它应该是这样的:
有谁知道解决方案?
这是我的列表导航代码:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,new String[] { "Item 1","Item 2" }); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(adapter,new ActionBar.OnNavigationListener() { @Override public boolean onNavigationItemSelected(int itemPosition,long itemId) { return true; } }); getSupportActionBar().setSelectedNavigationItem(0)
这些是我使用的样式集合.
<style name="CustomTheme" parent="@style/Theme.customized"> <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item> <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item> <item name="actionDropDownStyle">@style/CustomSherlockDropDownNav</item> <item name="android:actionDropDownStyle">@style/CustomSherlockDropDownNav</item> <!-- didn't work: https://stackoverflow.com/questions/12395381/android-actionbar-navigation-spinner-text-color <item name="android:spinnerDropDownItemStyle">@style/custom.Widget.DropDownItem.Spinner</item> <item name="spinnerDropDownItemStyle">@style/custom.Widget.DropDownItem.Spinner</item> --> <!-- didn't work: https://stackoverflow.com/questions/11479186/styling-actionbar-dropdown-menu <item name="android:actionBarWidgetTheme">@style/custom.actionBarWidgetTheme</item> <item name="actionBarWidgetTheme">@style/custom.actionBarWidgetTheme</item> --> <!-- didn't work: http://android-developers.blogspot.de/2011/04/customizing-action-bar.html <item name="android:dropDownListViewStyle">@style/CustomDropDownListView</item> <item name="dropDownListViewStyle">@style/CustomDropDownListView</item> --> .... </style> <style name="custom.actionBarWidgetTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar"> <item name="android:spinnerDropDownItemStyle">@style/custom.Widget.DropDownItem.Spinner</item> </style> <style name="custom.Widget.DropDownItem.Spinner" parent="@style/Widget.Sherlock.DropDownItem.Spinner"> <item name="android:textAppearance">@style/custom.TextAppearance.Widget.DropDownItem</item> </style> <style name="custom.TextAppearance.Widget.DropDownItem" parent="@style/TextAppearance.Sherlock.Widget.DropDownItem"> <item name="android:textColor">#00A000</item> </style> <style name="CustomDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown"> <item name="android:textColor">#00A000</item> <item name="android:textSize">8dip</item> </style> <style name="CustomSherlockDropDownNav" parent="@style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar"> <item name="android:popupBackground">@drawable/menu_dropdown_panel_customtab</item> <item name="android:background">@drawable/spinner_background_ab_customtab</item> </style>
然而,没有什么不起作用.
解决方法
问题是您使用相同的资源android.R.layout.simple_dropdown_item_1line作为微调器项和微调器下拉项.
请改用R.layout.sherlock_spinner_item和R.layout.sherlock_spinner_dropdown_item.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.sherlock_spinner_item,"Item 2" }); adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
这样,像Widget.Sherlock.TextView.SpinnerItem这样的样式就可以了.