我需要完全自定义的溢出菜单项(不同的背景颜色为最小的图片作为显示)。
可能吗?
我需要完全自定义的溢出菜单项(不同的背景颜色为最小的图片作为显示)。
可能吗?
最后一天,我必须实现操作栏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 这里。
您可以设置每个菜单项自定义视图。
@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
这一个https://stackoverflow.com/a/14123377/2069363对我的作品!
您可以使用微调(或IcsSpinner为ActionBarSherlock)在菜单项的操作布局这样的行为。 虽然你必须使用一个小技巧 - 隐藏当前选定的项目。