-1

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 :

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
soheila
  • 87
  • 1
  • 1
  • 9

2 Answers2

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
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