Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding buttons to android action bar

How can i make the buttons with text,with images in action bar like below.

Is it possible to use Inbuilt android button or image button to do like below in action bar.

I am using appcompat to use action bar.

enter image description here

like image 701
saravanan Avatar asked Oct 13 '13 14:10

saravanan


People also ask

How do I add actions to my toolbar?

From the Menu bar, click View > Toolbars > Customize. The Customize dialog and toolbar must be is displayed to perform this action. From the source toolbar to move the icon from, drag the icon holding down the mouse button to the target toolbar. Repeat for each icon to move.


2 Answers

Yes, you can inflate a custom actionbar if you need.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LayoutInflater inflater = (LayoutInflater) getActionBar()
            .getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    View customActionBarView = inflater.inflate(R.layout.actionbar_custom, null);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(
            ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
                    | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView,
            new ActionBar.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

    setContentView(R.layout.activity_main);
}

Where actionbar_custom.xml would be your layout resource, usually a LinearLayout with whatever components you want.

like image 88
ivagarz Avatar answered Sep 20 '22 12:09

ivagarz


You mean action items?http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems

You need to create a menu layout, as the guide mentioned above describes.

The default icon set for Android could be found here: http://developer.android.com/design/downloads/index.html

like image 38
elimirks Avatar answered Sep 20 '22 12:09

elimirks