0

我的菜单选项有问题。我正在使用操作栏 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);       
    }

对我有什么想法吗?
如果有代码示例很高兴

4

1 回答 1

0

使用简单的 ActionBar 或 ActionBarSherlock 将无法做到这一点。您将不得不自己处理菜单项单击并显示ListPopupWindow。提供ListPopupWindow一个适配器来显示您所描述的项目,就像您使用任何 ListView 一样。

于 2013-05-16T18:24:43.463 回答