How to display both icon and title of action inside ActionBar?

前端 未结 10 2025
庸人自扰
庸人自扰 2020-11-29 18:08

I need to display both icon and title of action inside ActionBar.

I\'ve tried \"withText\" option, but it has no

10条回答
  •  北海茫月
    2020-11-29 18:59

    You can create actions with text in 2 ways:

    1- From XML:

    
    

    When inflating the menu, you should call getSupportMenuInflater() since you are using ActionBarSherlock.

    2- Programmatically:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuItem item = menu.add(Menu.NONE, ID, POSITION, TEXT);
        item.setIcon(R.drawable.drawable_resource_name);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    
        return true;
    }
    

    Make sure you import com.actionbarsherlock.view.Menu and com.actionbarsherlock.view.MenuItem.

提交回复
热议问题