2013-02-13 101 views
4

我需要制作完全自定义的溢出菜单项(不同的背景颜色至少如图所示)。Actionbar样式的溢出菜单项

https://dl.dropbox.com/u/7771649/overflow.png

这可能吗?

+0

它是[可以改变*全部*溢出菜单项的颜色](https://groups.google.com/forum/?fromgroups#!topic/actionbarsherlock/5lHOKNlXn_4),但我不相信可以单独设置它们。 – Eric 2013-02-13 17:57:28

+0

但我需要为每个项目不同的样式。我知道一种方法 - PopupWindow具有自己的布局。但它不像操作栏中的弹出式菜单那么优雅。 – user2069363 2013-02-13 18:03:13

+0

您可以实现此设置您的动作列表的适配器。在适配器中,您可以设置不同的背景颜色。 – 2013-02-13 18:03:39

回答

5

最后一天,我必须实现操作栏Sherlock.And我的情况是一样的你。我有落实适配器为我导航List.Let说:

public class MyNavigationAdapter extends BaseAdapter { 
    Context mContext = null; 
    String[] mTitles; 
    LayoutInflater mLayOutInflater = null; 

    public MyNavigationAdapter(Context context, String[] titles) { 
     this.mContext = context; 
     this.mTitles = titles; 
     mLayOutInflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public int getCount() { 
     return mTitles.length; 
    } 

    @Override 
    public Object getItem(int arg0) { 
     return null; 
    } 

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

    @Override 
    public View getView(int position, View view, ViewGroup parent) { 
     if (view == null) 
      view = mLayOutInflater.inflate(R.layout.my_list_custom_row, parent,false); 
     TextView rowName = (TextView) view.findViewById(R.id.title); 
     rowName.setText(mTitles[position]); 
     rowName.setBackground(your desire drawle);// yo 

u can also set color etc. 
//OR 

if(position%2==0) 
     rowName.setBackgroundColor(Color.RED); 
     else 
      rowName.setBackgroundColor(Color.BLUE); 
     return view; 
    } 

} 

在这之后,你必须写在你的活动,这些行代码的onCreate methos。

ActionBar actionBar = getActionBar(); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 
actionBar.setListNavigationCallbacks(mNavigationAdapterObj, mNavigationListner); 

了解更多信息.Consult here.

+0

好的解决方案!但我更喜欢这一个:http://stackoverflow.com/a/14123377/2069363因为它允许我创建与溢出菜单图标在原来的溢出菜单相同的地方微调。 – user2069363 2013-02-13 18:44:26

+0

是的,你也可以添加图标,如果你想。如果你愿意,我可以更新我的答案。 – 2013-02-13 18:52:36

+0

是同样的解决方案,基本主题是一样的。接受我的回答。 – 2013-02-13 18:54:48