删除位于操作栏上的微调器标题的背景颜色

时间:2014-12-24 07:54:08

标签: android xml android-adapter

我正在发布输出的图片,我的旋转器的背景设置为白色,但是从操作栏上显示的微调器dropdown中选择的项目标题也会获得其背景颜色设置为白色,我该如何删除它?

我尝试了所有可能的方法,例如更改样式文件夹中的样式以及更改清单文件中的主题。         任何帮助。![在此输入图像描述] [1]

  [1]: http://i.stack.imgur.com/8Jcts.jpg

我的代码,因为我正在创建操作栏下拉导航

 /*         ACTION BAR : OVERFLOW MENU              */             
          getOverflowMenu();

    /*      for navigation menu     */

    actionBar = getActionBar();                           

     // Hide the action bar title

    actionBar.setDisplayShowTitleEnabled(false);actionBar.getSelectedNavigationIndex();                               

    // Back Button

    getActionBar().setDisplayHomeAsUpEnabled(true);

     // Enabling Spinner dropdown navigation


    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

      // Spinner title navigation data              


    navSpinner = new ArrayList<SpinnerNavItem>();
                navSpinner.add(new SpinnerNavItem("Drinks", R.drawable.menu_drinks_icon));
                navSpinner.add(new SpinnerNavItem("Home", R.drawable.home_icon));
                navSpinner.add(new SpinnerNavItem("Recipes", R.drawable.menu_recipes_icon));
                navSpinner.add(new SpinnerNavItem("Remedy", R.drawable.menu_remedies_icon)); 

                // title drop down adapter


     adapter = new TitleNavigationAdapter(getApplicationContext(), navSpinner);

                    // assigning the spinner navigation     


  actionBar.setListNavigationCallbacks(adapter, this);

适配器代码

    public class TitleNavigationAdapter extends BaseAdapter {

                 private ImageView imgIcon;
                    private TextView txtTitle;
                    private ArrayList<SpinnerNavItem> spinnerNavItem;
                    private Context context;

                 public TitleNavigationAdapter(Context context,
                            ArrayList<SpinnerNavItem> spinnerNavItem) {
                        this.spinnerNavItem = spinnerNavItem;
                        this.context = context;
                    }


                 @Override
                    public int getCount() {
                        return spinnerNavItem.size();
                    }

                 @Override
                    public Object getItem(int index) {
                        return spinnerNavItem.get(index);
                    }


                 @Override
                    public long getItemId(int position) {
                        return position;
                    }



     // for image


 @Override
                    public View getView(int position, View convertView, ViewGroup parent) { 
                        if (convertView == null) {
                            LayoutInflater mInflater = (LayoutInflater)
                                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
                            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);
                        }
                        imgIcon = (ImageView) convertView.findViewById(R.id.imgIcon);
                        txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);

                        imgIcon.setImageResource(spinnerNavItem.get(position).getIcon());
                        imgIcon.setVisibility(View.GONE);
                        txtTitle.setText(spinnerNavItem.get(position).getTitle());
                        return convertView;
                    }


     // for text
                 @Override
                    public View getDropDownView(int position, View convertView, ViewGroup parent) {
                        if (convertView == null) {
                            LayoutInflater mInflater = (LayoutInflater)
                                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
                            convertView = mInflater.inflate(R.layout.list_item_title_navigation, null);
                        }

                        imgIcon = (ImageView) convertView.findViewById(R.id.imgIcon);
                        txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);

                        imgIcon.setImageResource(spinnerNavItem.get(position).getIcon());        
                        txtTitle.setText(spinnerNavItem.get(position).getTitle());
                        return convertView;
                    }

            }

适配器的Xml:

     <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:padding="5dp"
        android:background="@color/spinner_color" >

        <ImageView 
            android:id="@+id/imgIcon"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ic_launcher"
            android:layout_marginRight="5dp"
            />

        <TextView android:id="@+id/txtTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/imgIcon"
            android:textColor="@color/black"
            android:fontFamily="OpenSans-Regular"
            android:textSize="16sp"/>

    </RelativeLayout>
   android:background="@color/spinner_color" `this is making the dropdown color white`

1 个答案:

答案 0 :(得分:0)

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

<style name="Theme.myapp" parent="@style/Theme.Light.DarkActionBar">
    <item name="android:actionDropDownStyle">@style/myapp_DropDownNav</item>        
    <item name="android:actionBarWidgetTheme">@style/myapp.actionBarWidgetTheme</item>
</style>

<style name="myapp.actionBarWidgetTheme" parent="@style/Theme.">
     <item name="android:spinnerDropDownItemStyle">@style/myapp.Widget.DropDownItem.Spinner</item>
</style>

<style name="myapp_DropDownNav" parent="@style/Widget.Spinner.DropDown.ActionBar">
    <item name="background">@drawable/spinner_background_ab_myapp</item>
    <item name="android:background">@drawable/spinner_background_ab_myapp</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_myapp</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_myapp</item>
</style>

<style name="myapp.Widget.DropDownItem.Spinner" parent="Widget.DropDownItem.Spinner">
    <item name="android:textAppearance">@style/myapp.TextAppearance.Widget.DropDownItem</item>
</style>

<style name="myapp.TextAppearance.Widget.DropDownItem" parent="TextAppearance.Widget.DropDownItem">
    <item name="android:textColor">@color/black</item>
</style>

P.S。自定义android:spinnerDropDownItemStyle actionBarWidgetTheme更改文字外观