How can I set the ActionBar icons to the right and left and set its title to the center?
I can now put the title text to the center of it.
I want it similar to this screenshot :
Asked
Active
Viewed 132 times
-1

CodeWizard
- 128,036
- 21
- 144
- 167

soheila
- 87
- 1
- 1
- 9
-
Are you using material design? – Collins Abitekaniza Nov 23 '15 at 07:06
-
i desinged a xml layout for display title bar center – soheila Nov 23 '15 at 07:07
-
follow the link-[http://stackoverflow.com/questions/28408768/set-app-icon-to-right-side-in-activity-tool-bar](http://stackoverflow.com/questions/28408768/set-app-icon-to-right-side-in-activity-tool-bar) – sud Nov 23 '15 at 07:10
2 Answers
0
You can use your own layout for the top bar and then, you will just have to put your custom elements in it.
As follow:
android.support.v7.app.ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayUseLogoEnabled(false);
mActionBar.setDisplayHomeAsUpEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setDisplayShowHomeEnabled(false);
ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.topbarclassic,null);
mActionBar.setCustomView(actionBarLayout);
I'm using a custom layout I made, R.layout.topbarclassic
as a top bar.
Just use a LinearLayout with some gravity
to place your elements properly, and it's done! :)

Virthuss
- 3,142
- 1
- 21
- 39
-
thanks a lot, but I want to when clicked them . one of them open menu (sub items) – soheila Nov 23 '15 at 07:30
-
0
Try this
res/menu/main.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:id="@+id/app_icon"
android:icon="@drawable/your_app_icon"
android:title="@string/app_icon"
app:showAsAction="always"/>
And overide the onCreateOptionsMenu
in your java code
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}

Collins Abitekaniza
- 4,496
- 2
- 28
- 43