Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBar list navigation: different text color in header and pop up menu

I have a navigation list in my action bar that has a dark background. The pop menu however, has a white background.

So what I want to achieve is, that the item text color inside of the action bar is white whereas the items text color in the menu pop up are black.

This are two examples what I got so far:

bad examples

This is how it should look like:

planned

Does anyone know a solution?

This is my code for the list navigation:

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)

These is a collection of styles that I worked with.

<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: http://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: http://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>

However nothing didn't work.

like image 414
Trinimon Avatar asked May 02 '13 13:05

Trinimon


2 Answers

The problem is that you are using the same resource android.R.layout.simple_dropdown_item_1line for the spinner item and the spinner dropdown item.

Use R.layout.sherlock_spinner_item and R.layout.sherlock_spinner_dropdown_item instead.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
         R.layout.sherlock_spinner_item, new String[] { "Item 1", "Item 2" });
adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

This way, the styles like Widget.Sherlock.TextView.SpinnerItem will work.

like image 123
Matthias Robbers Avatar answered Oct 05 '22 19:10

Matthias Robbers


You can achieve this just creating your custom xml which will be your list item. Create your xml like this : custom_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:textSize="18sp"
    android:textColor="@color/holo_dark_red"
    android:paddingRight="110dip"
    android:layout_width="match_parent"
    android:layout_height="?attr/dropdownListPreferredItemHeight"
    android:textIsSelectable="false"
    android:ellipsize="marquee" />

and use it like this :

adapter.setDropDownViewResource(R.layout.custom_list_item);

That should do the trick (at least it's working in my apps).

like image 35
hardartcore Avatar answered Oct 05 '22 18:10

hardartcore