我的菜单选项有问题。我正在使用操作栏 sherlock,当我单击选项菜单时,文本在左侧对齐。
我希望我的选项菜单文本首先在右侧与图标对齐。
想法:
这是选项菜单代码:
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
super.onCreateOptionsMenu(menu, inflater);
// TWEAK: FC when inflated from XML
searchItem = (MenuItem) menu.add(getResources().getString(R.string.menu_search));
searchItem.setIcon(R.drawable.abs__ic_search);
searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
// Create the SearchView
SearchView searchView = new SearchView(getActivity());
searchView.setQueryHint(getResources().getString(R.string.search_hint));
searchView.setOnQueryTextListener(this);
// Collapse when focus lost
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus){
if(hasFocus) {
mListener.OnSearchClickListener();
} else {
searchItem.collapseActionView();
}
}
});
// Assign the SearchView to the menuItem
searchItem.setActionView(searchView);
final Context ct = getSherlockActivity().getBaseContext();
SubMenu subMenu1 = menu.addSubMenu("Action Item");
subMenu1.add("Sample").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item){
// Intent i = new Intent(getApplicationContext(), PlaceActivity.class);
// startActivity(i);
return false;
}
});
subMenu1.add("Sample2").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item){
Intent i = new Intent(getSherlockActivity().getApplicationContext(), FragmentPagerSupport.class);
startActivity(i);
return false;
}
});
subMenu1.add("Map").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item){
FChangeView();
return false;
}
});
//blabla
subMenu1.add("Help").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item){
// mMapFragment.FNearMe();
return false;
}
});
subMenu1.add("Current Location").setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item){
// mMapFragment.FCurrentLocation();
return false;
}
});
MenuItem subMenu1Item = subMenu1.getItem();
subMenu1Item.setIcon(R.drawable.menu);
subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
对我有什么想法吗?
如果有代码示例很高兴