Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set menu items to the left side of actionbar?

I am making an android application which has an actionbar and the actionbar contains the menu items on both sides. So, I need to add one menu item at left side and one menu item at right side of the actionbar.

For this i have created a custom layout and set it to the action bar. As shown in the below image

action bar having custom layout

but i just want to have menu items at the places of left side and right the other screenshot shows the action bar with menu items

actionbar with menu itemss

In this the actionbar contains the menu items. So, i just want the put the plus button menu item to the left as same the first screen shot but i dont want to use the custom layout for this,

Also i need to chnage the font style of the actionbar title and put it in center.

Please help me. I spent many hours on this.

Thank You

like image 895
Manish Agrawal Avatar asked Oct 10 '14 08:10

Manish Agrawal


People also ask

How do I customize my action bar?

This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is the difference between ActionBar and toolbar?

An Action bar is traditionally a part of an Activity opaque window decor controlled by the framework but a Toolbar may be placed at any level of nesting within a view hierarchy. The toolbar provides more feature than ActionBar . A Toolbar may contain a combination of elements from start to end.


1 Answers

You can directly add navigation drawable to your toolbar try this code :

yourToolbar.setNavigationIcon("Resource id")

yourToolbar.setNavigationOnClickListener(new ClickListener(){})
like image 193
hiten pannu Avatar answered Oct 04 '22 21:10

hiten pannu