saravanan
saravanan

Reputation: 5397

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

Upvotes: 6

Views: 31953

Answers (2)

ivagarz
ivagarz

Reputation: 2444

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.

Upvotes: 12

elimirks
elimirks

Reputation: 1472

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

Upvotes: 3

Related Questions