4

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

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

可能吗?

4

3 回答 3

5

最后一天我必须实施 Action Bar Sherlock。我的情况和你的一样。我已经为我的导航列表实现了适配器。让我们说:

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;
    }

}

在此之后,您必须在您的 Activity onCreate 方法中编写这行代码。

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

欲了解更多信息。请在此处咨询。

于 2013-02-13T18:37:53.853 回答
0

这个https://stackoverflow.com/a/14123377/2069363对我有用!

您可以在菜单项的操作布局中使用 Spinner(或 ActionBarSherlock 的 IcsSpinner)创建此类行为。尽管您必须使用一个小技巧 - 隐藏当前选定的项目。

于 2013-02-13T18:42:14.597 回答
0

您可以为每个 MenuItem 设置自定义视图。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("test").setActionView(R.layout.custom_action_menu_item);
    return super.onCreateOptionsMenu(menu);
}

http://developer.android.com/reference/android/view/MenuItem.html#setActionView%28int%29

于 2013-02-13T18:01:01.467 回答