By urSus

2012-10-05 16:05:15 8 Comments

How could I make an actionbar to have logo in the center and two action items on sides like this?

enter image description here

I will be using ActionBar Sherlock.


@dennisdrew 2012-10-05 17:10:20

As I noted in a comment, I am not exactly sure if any of this would change with ABS (I'm sure not much would), but with the standard Action Bar you can load a custom layout .xml for your action bar title. For example, you could have action_bar_title.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
    android:background="@drawable/your_desired_background" >



Then, in your Activity, you would want to call a method like this in onCreate():

private void setupActionBar() {
        ActionBar ab = getActionBar();
        LayoutInflater inflator = (LayoutInflater) this
        View v = inflator.inflate(R.layout.action_bar_title, null);

        TextView titleTV = (TextView) v.findViewById(;
        Typeface font = Typeface.createFromAsset(getAssets(),



To take control of the left action item, you could do this in your Activity:

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
                        //do something
                        return true;
        case //<-- this will be your left action item
            // do something
            return true;
            return super.onOptionsItemSelected(item);

Of course, make sure you also do the other necessary setups for the Action items in your menu xml's as well. This will be for any right-sided action items.

Edit: Just saw in another comment you said that title would be an image. If that's the case, just replace the TextView I used in my example with your ImageView, and disregard the font customization code in the setupActionBar() method.

Edit2: I updated my Java code. You will need to do ab.setHomeAsUpEnabled(true), and then have a custom theme to implement an invisible (or perhaps @null although I don't know if Android will accept that) drawable for the home as up indicator. See here (taken from answer here:)

<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
    <item name="android:homeAsUpIndicator">@drawable/my_fancy_up_indicator</item>
    <!-- or you could try @null -->

@urSus 2012-10-05 17:39:22

so the solution to the action item on the left would be to fake it using UP button as I wrote in the first comment, right?

@dennisdrew 2012-10-05 17:44:11

Yes, and you would want to add a custom style for android:homeAsUpIndicator so you don't get that left chevron indicator. I will update with more code.

@Massimo Variolo 2013-04-04 09:56:53

How can I hide the arrow without android:homeAsUpIndicator? It requires API level 11 and my minimum is 8

@dennisdrew 2013-04-05 15:35:42

Are you using ActionBarSherlock?

@J. K. 2013-10-12 09:14:21

How is it done with Sherlock? I want to support API10

@Pranav Mahajan 2014-09-03 10:25:47

Is it possible to do this once, say in Application class rather than doing this in every Activity?? How??

@Pranav Mahajan 2014-09-03 10:42:37

Actually we should create our own MyActivity extends Activity & do it once there.

@Mahdi 2015-01-12 16:54:58

@dennisdrew thanks for solution. but is there a way that I put dropdown title to the center. ( not just title)?

@Sharone Lev 2019-09-06 09:15:57

This only worked for me after adding actionBar.setDisplayShowCustomEnabled(true);

Related Questions

Sponsored Content

40 Answered Questions

[SOLVED] How to add dividers and spaces between items in RecyclerView?

35 Answered Questions

[SOLVED] How can I center an absolutely positioned element in a div?

24 Answered Questions

[SOLVED] How do I hide a menu item in the actionbar?

21 Answered Questions

[SOLVED] How to get the ActionBar height?

52 Answered Questions

65 Answered Questions

[SOLVED] How do I center text horizontally and vertically in a TextView?

  • 2009-01-11 00:27:55
  • pupeno
  • 1260230 View
  • 2054 Score
  • 65 Answer
  • Tags:   android textview

17 Answered Questions

[SOLVED] How do I change the android actionbar title and icon

9 Answered Questions

[SOLVED] How to customize the back button on ActionBar

7 Answered Questions

Sponsored Content